Friday, September 20, 2013

How To: Add Gradle support to a Maven project

In 2010 I started working on Confluence/Jira Plugins (written in Java) for Adaptavist. My programming experience back then consisted of small projects with little or no dependencies and no automated tests, so landing a job at a software company was a big eye opener. It was during this time that I was introduced to Maven. Having the ability to define a projects dependencies and build process so that any other developer can easily compile the same project without needing to waste time configuring their dev environment is certainly a big win. It made a huge impression on me and I have been an advocate of Maven ever since.

While working at Adaptavist I had the good fortune to attend Devoxx in Belgium. During the conference I heard about Gradle but didn't pay it much mind as my day to day work was so geared around a specific set of tools. Since that time I've been involved in a few Android projects. Although there is an android-maven-plugin, I found trying to build Android projects using Maven considerably painful; this is due partly to the fact that an Android project structure does not fit well with the conventions that Maven uses.
"Gradle combines the power and flexibility of Ant with the dependency management and conventions of Maven into a more effective way to build"
Recently I came across this page showing the progress of Gradle support in the Android SDK. This prompted me to do a little reading about Gradle to see if it could help make Android development a little less troublesome. Starting with the android.com why Gradle page, and some good presentations on youtube I decided to download and install the latest version (1.7 at time of writing).

Installation is easy, just the same as Maven and most other tools. Set an environment variable called GRADLE_HOME and then make sure %GRADLE_HOME%\bin is on your PATH variable (same kind of thing for Linux & Mac). Once that's done just run 'gradle -v' from the command line to make sure it's setup correctly.

Thankfully the Gradle developers have made it easy for people to add Gradle support to existing Maven projects. In the root folder of your project just run 'gradle setupBuild' and Gradle will detect your pom file and create a 'build.gradle' file using the same dependencies and build settings.

No comments: