Skip to main content


Kuruthi - a bold effort

It is difficult to do anything in the entertainment industry these days without offending the sensibilities of someone -  by gender, religion, caste or any other aspect -  you name it. Kuruthi (spelt ഗുരുതി in Malayalam)   is an interesting take on how two families in a remote village are affected by events outside their control. There is Ibrahim (Ibru), grieving for his wife and daughter, who passed away in a landslide in his village. He stays with his father and younger brother.  His neighbour Suma lives with her brother, whose family is also a victim in the landslide.  They earn their living tapping toddy and climbing trees. Suma brings food to Ibru's home.  They are fond of each other, Ibru doesn't want to take the relationship beyond that fearing society. Chaya kada (Coffee shops in the mallu world) discussions are about how life is not fair.  Everyone has their grievance. Ibru's brother Rasool is outspoken and is influenced by these discussions. On a late evening, as

Converting a maven project to gradle

Updated:  13 July 2014

With gradle 2.0 released on 1st July 2014, it was time to relook and update this write-up suitably.  gradle is in active development and has evolved a lot.  It is now the new android build tool.

I had tried using Gradle a few months back without much success.

Last week, I decided to give another shot, after seeing that many popular open source projects (hibernatespring security to name two) were using gradle.

I downloaded the latest version as of date (0.9-rc-3). (2.0 as on 13th July 2014).

Installation is straightforward, since it is just extracting the zip file and updating the PATH to refer to the bin folder of the unzipped contents.

gradle -version

ran without errors, indicating that installation went off fine.

Downloading and installing gradle is straight-forward.  Unzip the binaries to a folder of your choice, set GRADLE_HOME to this folder and add the bin subfolder of GRADLE_PATH to your PATH variable.

On Windows, it would be something like below:

set GRADLE_HOME=C:\software\gradle-2.0 


gradle -v 

Gradle 2.0 

Build time: 2014-07-01 07:45:34 UTC 
Build number: none Revision: b6ead6fa452dfdadec484059191eb641d817226c 

Groovy: 2.3.3 
Ant: Apache Ant(TM) version 1.9.3 compiled on December 23 2013 
JVM: 1.7.0_60 (Oracle Corporation 24.60-b09) 
OS: Windows 8.1 6.3 amd64

So far so good.

Now the idea was to create a gradle build script for an existing maven project. The best way to start off was by looking at the documentation.

There is no shortage of information, but my idea was not to learn gradle from a to z, but to see how quickly I could create a build script for my maven project.  I looked around but could find nothing like a one-to-one mapping of maven pom.xml to build.gradle.

There is a gradle build init plugin, which can be applied on a maven pom to bootstrap a gradle script.  It does a simple one-to-one conversion of maven dependencies to gradle, but not much beyond.  For instance, it did not automatically apply 'war' plugin. It also did not detect I was using testNG.

I did find some examples for maven in samples folder of gradle installation.  However, the best resource that I hit upon was the build script of spring security itself [build.gradle, javaprojects.gradle].

Here is what I did to enable a gradle build for my maven project.  Remember, we are looking at a simple typical maven project and this is not an exhaustive guide.

We start by specifying to gradle that we need to build java, maven project

apply plugin: 'java'
apply plugin: 'maven'

In addition, if we need to build a war (as in my case),

apply plugin: 'war'

Gradle uses build folder by convention to do the build and generate artifacts.  To use maven's target folder,

// Change default directory to target from build

buildDir = 'target'

Specifying versions of libraries (or other properties)

In Maven, it would be something like...

<properties> <

In gradle:

ext {
    springVersion = '4.0.5.RELEASE'
    securityVersion = '3.2.4.RELEASE'
    slf4jVersion = '1.7.7'
    logbackVersion = '1.1.2'

Specifying the version and group of the project artifact




group = 'net.sourceforge.jukebox'
version = '1.0-SNAPSHOT'

Specifying location of repository (holding 3rd party dependencies)

Maven gathers this from settings.xml

Gradle (assuming Maven local repository is in the default location):

repositories {
    // First check local cache before accessing central repository
    mavenRepo name:'Local', urls: "file://" +['user.home'] + "/.m2/repository"

Specifying the 3rd party dependencies.

In Maven, a dependency can have the following scope
  • compile (the default)
  • test
  • runtime
  • provided
Also, by default maven dependencies are transitive

To make it similar in gradle,

configurations {
    testCompile.extendsFrom provided
    compile.transitive = true

dependencies {

        [group: 'ch.qos.logback', name : 'logback-classic', version : logbackVersion],
        [group: 'ch.qos.logback', name : 'logback-core', version : logbackVersion],
        [group: 'commons-configuration', name : 'commons-configuration', version : '1.6']

    providedCompile group: 'javax.servlet', name : 'servlet-api', version : '2.5'

        [group: 'org.mockito', name : 'mockito-core', version : '1.8.5'],
        [group: 'org.springframework', name : 'spring-test', version : springVersion],
        [group: 'org.testng', name : 'testng', version : '5.14.2']
        [group: 'org.slf4j', name : 'log4j-over-slf4j', version : slf4jVersion],
        [group: '', name : 'spring-security-config', version : securityVersion],
        [group: '', name : 'spring-security-web', version : securityVersion]

Now to ensure that the dependencies in the provided scope are available in compile classpath  Dependencies in providedCompile group are available in compile classpath.

// Added the provided dependency to compile classpath
sourceSets.main.compileClasspath += configurations.provided

Now, if you use testNG instead of junit for unit testing, then

// Use TestNG instead of the default JUnit
test {

That is it!  With these configuration,  the following command does the equivalent of maven clean package

gradle clean test war

In case you are interested, you can compare the pom.xml and the equivalent build.gradle here


  1. I have had success on several project with this simple converter.


  2. Instead of

    // First check local cache before accessing central repository
    maven {
    url "file:///" + localRepoDir + "/.m2/repository"

    you can just use mavenLocal()

  3. Nice article to write gradle file from beginning. I tried to come up with one more article to convert pom file to gradle build file
    converting parent pom to gradle init file

    Let me know your feedback.

  4. Thanks for posting such a Useful information .You done a great job.
    and also we are providing E-Learning Portal Videos for students and working Professionals
    Hurry Up! Bag All Courses in Rs - 10000 /- + taxes
    41 Career building courses.
    Designed by 33 industrial experts
    600+ hours of video Content
    DevOps and Cloud E-Learning Portal

  5. This comment has been removed by a blog administrator.

  6. This comment has been removed by a blog administrator.

  7. I just loved your article on the beginners guide to starting a blog.If somebody take this blog article seriously in their life, he/she can earn his living by doing blogging.thank you for thizs article. best devops online training

  8. This post is really nice and informative. The explanation given is really comprehensive and informative. devops training by 10+ years experienced faculty.


Post a Comment

Popular Posts