Simple Groovy project using Gradle

Hello fellow Groovyists 🙂

I have been kicking the tires on using Gradle for my Groovy projects. I had a few stumbles along the way and wanted to share what I came up with for getting a very simple example working.

build.gradle

apply plugin: 'groovy'
version = "1.0-${new Date().format('yyyyMMdd')}"

manifest.mainAttributes("Main-Class" : "com.javazquez.HelloThere")

repositories {
    mavenCentral()
    mavenRepo urls: "http://groovypp.artifactoryonline.com/groovypp/libs-releases-local"
}
dependencies {
    groovy group: 'org.codehaus.groovy', name: 'groovy-all', version: '1.8.4'
    groovy group: 'org.mongodb', name: 'mongo-java-driver', version: '2.6.5'
    groovy group: 'com.gmongo', name: 'gmongo', version: '0.9.1'
    testCompile "org.spockframework:spock-core:0.5-groovy-1.8"
}

jar {
    from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
}

below is the the HelloThere.groovy file located src/main/groovy/com/javazquez/HelloThere

package com.javazquez
public class HelloThere {

    public static void main(String []args) {
        println "Hello coders!"
    }
}

after running gradle build, I can navigate to the build/libs directory and run java -jar HelloThere-1.0-20111115.jar and get the following ouptut

Hello coders!

Gradle is a fantastic tool and I hope this article helps show the ease of getting a project set up.