Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create a Groovy executable JAR with Gradle

Tags:

gradle

groovy

This is my gradle build script.

apply plugin: 'groovy'  project.group = "test.tree" archivesBaseName = "tree" project.version = "1.0" manifest.mainAttributes("Main-Class" : "test.tree.App")  sourceCompatibility=1.6 targetCompatibility=1.6  repositories {     mavenCentral() }  dependencies {     groovy group: 'org.codehaus.groovy', name: 'groovy', version: '1.8.6'     testCompile group: 'junit', name: 'junit', version: '4.8.2' } 

And this compiles just fine

The problem is that I can't run the created JAR, I get an exception java.lang.NoClassDefFoundError: groovy/lang/GroovyObject

So I guess the groovy plugin doesn't include all the necessary classes inside the JAR.

How to I create a stand-alone JAR that I can simply .. run ;-)

like image 931
emesx Avatar asked Mar 17 '12 10:03

emesx


1 Answers

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'     } } 
like image 83
Benjamin Muschko Avatar answered Sep 28 '22 01:09

Benjamin Muschko