Testing plugin compatibility against Gradle versions

(Schalk Cronjé) #1

A recommendation (definitely endorsed by yours truly) is to write plugins against Gradle 2.0. The idea is that it would then be compatible with further 2.x releases. (This has been discussed at Minimum Gradle version for developing plugins).

However sometimes the lovely folks at Gradleware (and other contrbutors) do not always get it right i.e some issues between 2.1 & 2.2. I also got stung by this recently and I’m sure I’m not the only plugin author who will be. Testing compatibility manually is an arduous task, so why not automate it.

Therefore I would like to announce a new plugin org.ysb33r.gradletest which does exactly that. It is already on the portal as a 0.5 release (https://plugins.gradle.org/plugin/org.ysb33r.gradletest). It is still rough around the edges and I have highlighted the things I would like to see as Github issues over at https://github.com/ysb33r/gradleTest. Howver, it does that core job correctly - it tests your plugin against various Gradle versions.

It runs every test in isolation running up a new JVM with an instance of Gradle. It is therefore an expensive tests and is not run as part of the test chain - you need to ./gradlew gradleTest to get it to run. To use it see the information in the README as it quite extensive. But for now here is some taster information.

Create a folder in your project src/gradleTest. Every direct child folder on gradleTest will become a test as long as it contains a build.gradle file. This file needs to contain a entry task called runGradleTest which could be an empty task which only depends on tasks that your plugin adds. By example you can have

src / gradleTest / myTest / build.gradle
                          / src

The layout below myTest would be as for any Gradle project. It I were to test the GnuMake plugin for instance then the content of myTest/build.gradle would be something like

buildscript {
  dependencies {
    classpath 'org.ysb33r.gnumake:gnumake:%%VERSION%%'
  }
}

apply plugin : 'org.ysb33r.gnumake'

task runGradeTest { dependsOn make }

The gradleTest plugin will substitute the current verson on your plugin if you use the %%VERSION%% token. It will also make the plugin available on the classpath so that it can be found.

All you need to do in your project build.gradle is to tell it which Gradle versions to test against.

gradleTest {
  versions '2.1','2.2'
}

There is a lot more you can configure - see the README for that. However you are pretty much ready to go testing now. Happy hunting!

It you would like to help with those last bits mentioned on Github in the issues and the README I would really appreciate it. PRs welcome!