These are a variety of plugins that I wrote for Gradle and figured I'd share with the world.
All of the plugins below have the class name com.smokejumperit.gradle.NameOfPlugin
. So AllPlugins
is com.smokejumperit.gradle.AllPlugins
, and EnvPlugin
is com.smokejumperit.gradle.EnvPlugin
. And so on.
Convenience plugin that loads all the plugins listed below.
Provides the ability to keep external dependency names and versions in one location, and use them throughout
a number of projects. By assigning a Java identifier as a key and a configuration spec as a value in a
properties file, that identifier becomes available in the dependencies
configuration block.
The definitions can either be defined globally or in the root directory of the project, with the root directory definitions replacing global definitions.
In your ~/.gradle/dependencies.properties
:
commonsLang: commons-lang:commons-lang:2.5
In your $ROOTDIR/dependencies.properties
:
commonsIo: commons-io:commons-io:2.0
In your build.gradle
:
apply plugin:com.smokejumperit.gradle.DepNamesPlugin
apply plugin:'java'
repositories {
mavenCentral()
}
dependencies {
compile commonsLang
}
Result: You now have commonsLang in your classpath.
Provides the oneJar
task to generate a single executable jar containing dependencies.
Uses one-jar under the hood.
The resulting jar file will be next to the standard jar, but with '-fat' attached to the name.
To use the OneJar plugin, you have to specify a main class in your MANIFEST file. To do this,
provide something like the following in your build.gradle
file:
jar {
mainfest {
attributes 'Main-Class': 'com.bigmoney.hugeproject.Main'
}
}
Provides tasks to compile JavaCC/JJTree files. Apply the plugin and use -t
to get details on the tasks if you want to call them
directly: otherwise, the parser will be generated and the files compiled as a prelude to compileJava
, and the resulting parser
will be placed into the archive of the jar
task.
The JAVACC_HOME
environment variable (that's environment variable, not Java property) must be set to the home directory of
the JavaCC installation, as per the javacchome
parameter of the Ant javacc
task.
The source for JavaCC/JJTree (including *.java
support files) should be put in folder packages under
./src/javacc
--- it's not a source-set, so there's no java
or javacc
subdirectory. So if you want to generate your parser in com.smokejumperit.parser
, the location for the JJTree file
is ./src/javacc/com/smokejumperit/parser/myparser.jjt
. If you want to change that location, change the javaccSrcDir
property
of your project.
Java files (*.java
) adjacent to JavaCC or JJTree files (*.jj
or *.jjt
) will be deleted on clean. JavaCC files (*.jj
) adjacent
to JJTree files (*.jjt
) will be deleted on clean. Any *.java
files (or other files) not adjacent to a *.jj
and *.jjt
file will
survive a clean.
Provides two methods on the project
object to work with configuration classloaders:
-
classLoaderFor(String... configNames)
—Provides ajava.lang.ClassLoader
consisting of all of the dependencies in the named configurations, in the order specified. -
classFor(String className, String... configNames)
—Looks up the class for nameclassName
using the class loader for configs inconfigNames
.
Note that each call to one of these methods generates a new ClassLoader instance: this is a feature, not a bug, because it allows the ClassLoader to be garbage collected if it and its classes are done being consumed. This can be critical to saving PermGen space.
task(foo) << {
project.classFor("my.app.Main", bar).main()
}
Provides methods exec(cmd)
and exec(cmd, baseDir)
on the project to execute shell commands. If the command does not return 0, the build will fail.
project.exec("ls -al", project.buildDir)
Provides a map property on the project named env
consisting of the external system's environment variables. Also provides a method env(key)
on the project that will return a particular environment variable's value, and explode if it does not exist.
This is a holder for various extensions to the Project API.
// Attempt to make path relative to project if it is a subdir
project.tryRelativePath("/some/random/path/foo/bar/baz")
A plugin to run JRuby scripts and manage gems.
project.gemHome // Provides the location for where gems are installed
project.gemHome(String gemName) // Provides the root folder of the gem
project.gemScript(String gemName) // Provides the main script for the gem
project.runJRuby(String cmdArg, String[] configs=['runJRuby'])
project.useGem(String gemName) // Installs a gem (if not currently installed)
Runs Cucumber. Specifically, provides a task (runFeatures
) that executes the features, which are assumed to reside in ./src/test/features/
. By default, the classloader for the cuke
configuration is used when the features are executed. That configuration includes testRuntime
, runtime
, jruby
, and the classes generated from the test
and main
source sets.
To modify the defaults, change convention.plugin.cuke
. The configs
property of that object is a list of configurations to load when executing feature tests. The featuresDir
property of that object denotes where the root of the features reside. The stepsOutputDir
denotes the location of step definition classes and is passed to cuke via the --require argument.
This is an integration with Cuke4Duke: the ant
property of the project now has a cuke
task to execute Cucumber.
You may have to run with gradle -i
in order to see the Cucumber output.
Add the following lines to your build script to add the jars to your buildscript classpath and use the plugins:
// Example of using two plugins
apply plugin:com.smokejumperit.gradle.ClassLoadersPlugin
apply plugin:com.smokejumperit.gradle.ExecPlugin
buildscript {
repositories {
mavenRepo urls:'http://repo.smokejumperit.com'
}
dependencies {
classpath 'com.smokejumperit:gradle-plugins:0.6.8'
}
}
If you want to ust use all the SmokejumperIT plugins, you can do this:
apply plugin:com.smokejumperit.gradle.AllPlugins
buildscript {
repositories {
mavenRepo urls:'http://repo.smokejumperit.com'
}
dependencies {
classpath 'com.smokejumperit:gradle-plugins:0.6.8'
}
}
See the sample
directory of this project for a build script which does this.
These plugins were written by Robert Fischer. They are published at GitHub:RobertFischer/gradle-plugins.
Thanks to Jeppe Nejsum Madsen for some additional testing and work (found an NPE circumstance and supplied a patch).
All these plugins are licensed under the Creative Commons — CC0 1.0 Universal license with no warranty (expressed or implied) for any purpose.