Jan 18, 2012

Gradle Goodness

A few more of today's learnings in Gradle:

When migrating build script code to a plugin you will typically need to add project. in places (because the delegate of a Gradle build script is the project). You can use Project.configure to make the migration smoother, e.g.:

apply plugin: MyPlugin

class MyPlugin implements Plugin {
void apply(Project project) {
project.configure(project) {
version '1.0' // instead of project.version '1.0'
}
}
}
For testing your Gradle plugins you can use ProjectBuilder.builder().build() to test the wiring of your plugin. For integration testing there's GradleDistributionExecutor, BUT it's not publically exposed - so please vote for the testing toolkit roadmap item to see this feature sooner.

So you know about the Copy task. Ever find yourself wanting to be certain that the destination folder is clean of other output? use the Sync task. Very nice.

Find yourself wanting to configure all current and future tasks matching a certain criteria? Take a look at the project.tasks. E.g.:
tasks.withType(Jar) {
aProperty = 'value'
}
Enjoy!

No comments: