Monday, November 18, 2013

Convert Maven Project to Gradle in an instant

At first, I was very hesitant to convert all my Maven projects to Gradle because of the set-up and configurations I have to do. Though Gradle is Groovy-based, there is still much I need to know before I can accept it as I am accepting Maven now as my build automation tool. But things may change from now on. I discovered something good while playing around.

The Transition

I was about to create a Wicket project in Maven. As most Maven users know, we can "quickstart" a project using Maven Archetypes. And, Wicket happens to be a very fan of Maven ever since. Of course, they are both created by Apache.

Now, to start.

mvn archetype:generate -Dfilter=wicket

There will be displayed a lot of Maven Archetypes using Wicket as the Java Web Framework. I just chose the wicket-quickstart-archetype.

Then, I input groupId, artifactId, version, as usual.

When done, I change-directory'ed to the project's folder. I don't know the exact meaning of the Gradle task. But, I typed and entered

gradle setupBuild

Poop! It became Koko Gradle! Yeah, corny it may sound. But yes, I confirmed when I looked onto the build.gradle file.

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

group = 'com.sudocode.checkman'
version = '0.0.01'

description = """quickstart"""

sourceCompatibility = 1.6
targetCompatibility = 1.6



repositories {
     maven { url "http://www.sudocodesystems.com/nexus/content/groups/public" }        
     maven { url "https://repository.apache.org/content/repositories/snapshots/" }
     maven { url "http://repo.maven.apache.org/maven2" }
}
dependencies {
    compile group: 'org.apache.wicket', name: 'wicket-core', version:'6.12.0'
    compile group: 'org.slf4j', name: 'slf4j-log4j12', version:'1.6.4'
    compile group: 'log4j', name: 'log4j', version:'1.2.16'
    testCompile group: 'junit', name: 'junit', version:'4.11'
    providedCompile group: 'org.eclipse.jetty.aggregate', name: 'jetty-all-server', version:'7.6.13.v20130916'
}


I imported the project in IntelliJ IDEA to confirm. I just bumped into a problem on the highlighted text above. You have to change it to testCompile in able for Gradle to include the Jetty libraries.

Now, I am confident to migrate everything to Gradle. I never thought the command gradle setupBuild was that powerful.

No comments:

Post a Comment