Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
268 views
in Technique[技术] by (71.8m points)

Create a Groovy executable JAR with Gradle

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 ;-)

question from:https://stackoverflow.com/questions/9749032/create-a-groovy-executable-jar-with-gradle

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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'
    }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...