Create a Groovy executable JAR with Gradle

What you are looking for is the application plugin which allows you build a standalone JVM application including all dependencies and run scripts. apply plugin:’application’ mainClassName=”test.tree.App” EDIT: This should create the uberjar you want: task uberjar(type: Jar) { from files(sourceSets.main.output.classesDir) from configurations.runtime.asFileTree.files.collect { zipTree(it) } manifest { attributes ‘Main-Class’: ‘test.tree.App’ } }

Groovy : Closures or Methods

I only use closures where I need them, i.e. I use methods by default. I do this because Methods are simpler than closures. Closures have a delegate, an owner, retain access to variables that were in their local scope when created (what you call “free variables”). By default method calls within a closure are resolved … Read more

Running Groovy scripts from Gradle using a different version of Groovy

You can create directory src/main/groovy, put your script called myscript.groovy in there: println “hello world from groovy version ${GroovySystem.version}” Then, have a build.gradle file in your project root directory: apply plugin: ‘groovy’ repositories { mavenCentral() } dependencies { compile ‘org.codehaus.groovy:groovy-all:2.0.5’ } task runScript (dependsOn: ‘classes’, type: JavaExec) { main = ‘myscript’ classpath = sourceSets.main.runtimeClasspath } … Read more

What’s the operator

The << is a left-shift operator. In this scenario, task “task$counter” is a Task object declaration, and << is overloaded as an alias to the doLast method, which appends the closure to the list of actions to perform when executing the task. If you don’t specify the <<, the closure is treated as a configuration … Read more