Skip to content

RobertFischer/gradle-plugins

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Gradle Plugins

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.

Compilers

Compilers have been broken out into their own projects. See Gradle-Mirah-Compiler and Gradle-Javacc-Compiler.

AllPlugins

Description

Convenience plugin that loads all the plugins listed below.

DepNames Plugin

Description

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.

Example

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.

OneJar Plugin

Description

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.

Specifying a Main Class

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'
  }
}

ClassLoadersPlugin

Description

Provides two methods on the project object to work with configuration classloaders:

  • classLoaderFor(String... configNames)—Provides a java.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 name className using the class loader for configs in configNames.

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.

Example

task(foo) << {
  project.classFor("my.app.Main", bar).main()
}

ExecPlugin

Description

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.

Example

project.exec("ls -al", project.buildDir)

EnvPlugin

Description

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.

ProjectExtPlugin

Description

This is a holder for various extensions to the Project API.

Example

// Attempt to make path relative to project if it is a subdir
project.tryRelativePath("/some/random/path/foo/bar/baz")

RunJRubyPlugin

Description

A plugin to run JRuby scripts and manage gems.

API

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)

CukePlugin

Description

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.

Installation

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.8.2'
  }
}

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.8.2'
  }
}

See the sample directory of this project for a build script which does this.

Author and Origin

These plugins were written by Robert Fischer. They are published at GitHub:RobertFischer/gradle-plugins.

Additional Credit

Thanks to Jeppe Nejsum Madsen for some additional testing and work (found an NPE circumstance and supplied a patch).

License

All these plugins are licensed under the Creative Commons — CC0 1.0 Universal license with no warranty (expressed or implied) for any purpose.

About

Plugins for Gradle

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages