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.

1
2
3
configurations {
    catalinaAnt
}

And now the magic of dependencies management.

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

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
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:

1
2
<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.

1
2
3
configurations {
    coreClientLib
}

Then the dependency for that configuration,

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

And now the custom tag to unpack the jar file.

1
2
3
4
5
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.