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

Groovy console can’t “remember” any variables – always says “unknown property”

This is standard behavior in the Groovy shell, not peculiar to the Grails shell. You probably don’t want to def the variable. See the following: ~ $ groovysh Groovy Shell (2.3.4, JVM: 1.7.0_45) Type ‘:help’ or ‘:h’ for help. ——————————————————————————- groovy:000> def x = 42 ===> 42 groovy:000> x Unknown property: x groovy:000> y = … Read more

How to check if a String matches a pattern in Groovy

Groovy regular expressions have a ==~ operator which will determine if your string matches a given regular expression pattern. Example // ==~ tests, if String matches the pattern assert “2009” ==~ /\d+/ // returns TRUE assert “holla” ==~ /\d+/ // returns FALSE Using this, you could create a regex matcher for your sample data like … 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