Gradle wonders…

Well I was playing recently more with gradle to create a more “Continuous Integration” environment. And I found some interesting things about it, So I wanted to share them.

One is the easy integration it has with Ant tasks, you can even create your own tasks based on Ant, and then use them on Gradle. On this occasion I used the Ant tomcat task to deploy and redeploy into tomcat 7.x server.

configurations {
    catalinaAnt
}

And now the magic of dependencies management.

dependencies{
    catalinaAnt "org.apache.tomcat:tomcat-catalina-ant:7.0.0"
}

And now the magic of running and creating the tomcat tasks.

task tomcatStop << {
    ant.taskdef(
        'name':"stop",
        'classname':"org.apache.catalina.ant.StopTask",
        'classpath':configurations.catalinaAnt.asPath )
    ant.stop(
        'username':user,
        'path':path,
        'password':password,
        'url':url )
}

task tomcatStart << {
    ant.taskdef(
        'name':"start",
        'classname':"org.apache.catalina.ant.StartTask",
        'classpath':configurations.catalinaAnt.asPath )
    ant.start(
        'username':user,
        'path':path,
        'password':password,
        'url':url )
}

task tomcatReload(dependsOn:[clean, war]) << {
    ant.taskdef(
        'name':"reload",
        'classname':"org.apache.catalina.ant.ReloadTask",
        'classpath':configurations.catalinaAnt.asPath
    )
    ant.reload(
        'username':user,
        'path':path,
        'password':password,
        'url':url )
}

task tomcatStop << {
    ant.taskdef(
        'name':"stop",
        'classname':"org.apache.catalina.ant.StopTask",
        'classpath':configurations.catalinaAnt.asPath )
    ant.stop(
        'username':user,
        'path':path,
        'password':password,
        'url':url )
}

task tomcatStart << {
    ant.taskdef(
        'name':"start",
        'classname':"org.apache.catalina.ant.StartTask",
        'classpath':configurations.catalinaAnt.asPath )
    ant.start(
        'username':user,
        'path':path,
        'password':password,
        'url':url )
}

task tomcatReload(dependsOn:[clean, war]) << {
    ant.taskdef(
        'name':"reload",
        'classname':"org.apache.catalina.ant.ReloadTask",
        'classpath':configurations.catalinaAnt.asPath
    )
    ant.reload(
        'username':user,
        'path':path,
        'password':password,
        'url':url )
}

These Ant tasks uses the text interface for tomcat, so you need to enable it on the tomcat-users.xml file, Just like this:

<role rolename="manager-script">
<user username="tomcat" password="s3cr3t" roles="manager-script"/>

And also remember to replace the variables for the actual values of your tomcat configuration.

The other one is the ability of unpacking jar dependencies as zip under a desired directory on the project path. This helped me to use Maven as client side libraries repository (CSS, and JS files), to version it, deploy and upgrade more easily any user interface or jquery ui upgrades or any changes across multiple applications based in a core js and css libraries ( this sounded better in my head, anyways..). Let me show you how.

First we add the new configuration in the build.gradle file.

configurations {
    coreClientLib
}

Then the dependency for that configuration,

dependencies{
    coreClientLib 'com.elavena:client-core:1.0.3'
}

And now the custom tag to unpack the jar file.

task updateCoreLib (type: Copy){
    description = 'Task to update the core Client Library from the dependency coreClientLib'
    from( zipTree(configurations.coreClientLib.singleFile) )
    into config.coreFolder
}

This taks creates a zipTree from the new configuration (coreClientLib) jar and copies it ( hence the type: Copy on the gradle task) into the destination folder(config.coreFolder). Isn’t it nice?

And that is all I wanted to share for the moment. I am currently doing VM Conversions which is a nightmare, so I will put up some tips to convert VM machines if my head does not explodes first, or if stalk from office to office with an Armalite AR-10 carbine gas powered semi-automatic weapon pumping round after round into colleagues and co-workers. Whatever happens first… Just kidding,

el_avena off.