Thursday 5 April 2012

Gradle

I've been happily using Gradle for one year as my build management tool of choice. Gradle primary aim is to be used as build management tool for Java projects great and small. Gradle aims to offer build management with the power and flexibility of Ant and the dependency management of Maven. I think it has achieved both aims and a lot more.

Unlike Ant and Maven, Gradle chose to avoid using XML as the build scripting choice and instead use a domain specific language (Groovy in this case), which gives Gradle a far more declarative and expressive build scripting ability. Another handy feature of Gradle is the ability to build using the Gradle Wrapper, this is useful as it removes the hassle of installing Gradle on your development boxe or more importantly the overhead of system administration work involved in installing Gradle on all your development teams CI build sever agents.

Gradle uses a powerful task object model to define discrete items or essentially tasks in your build. Each task is defined as a type of DefaultTask in Gradle. Below is a very common task which most developers will have encountered, loading test data into a database for testing purposes.


task loadTestData {

dependsOn << createDatabaseSchema

println 'loading test data...'

}

task creatDatabaseSchema {

println 'creating database schema...'

}

$ gradle loadTestData
:loadTestData
creating database schema...
loading test data...


Gradle provides the dependsOn(task) feature adds a task as a dependency of the calling task. The depended-on task will always be called before the calling task.


References:

http://www.gradle.org/
O'Reilly Building and Testing with Gradle