Jan 17, 2012

Gradle Goodness

A little known fact is that in Gradle you can now change property assignments into method calls in your build scripts (essentially by omitting the equals sign). Here's the good part: if the property does not exist the build script will fail. Yay! No more silent typo bugs! To illustrate, this works:

version = '1.0'
As does this:
version '1.0'
But this build script will fail:
versionxxx '1.0'
Nice!

Another tip:

Rather than make use of afterEvaluate you may be able to make good use of lazy GStrings. For example you could define your project version as "version-${-> buildNumber}"! See the explanation of Groovy lazy GString syntax for more information.

Did you know that the --exclude-task (-x) command-line switch differs from skipping tasks in that it prunes away the whole task graph associated with the excluded task? I didn't!

Finally, if your company is putting a lot of effort into customizing the Gradle experience, did you know that you could take advantage of Gradle init scripts in the Gradle init.d folder? Yes? Fiddly though, isn't it? Did you know that you can bundle your custom init scripts inside a Gradle distribution?!

To use this you need to assemble a Gradle distribution zip (basically by adding your init.d scripts to it), make it available internally (say, in your Artifactory repository), and then simply edit your gradle/wrapper/gradle-wrapper.properties. In there is the URL to download the Gradle distribution (distributionUrl).

Enjoy!

No comments: