how to export a executable jar in gradle, and this jar can run as it include reference libraries

jychan picture jychan · Feb 1, 2013 · Viewed 39.5k times · Source

how to export a executable jar in gradle, and this jar can run as it include reference libraries.

build.gradle

apply plugin: 'java'

manifest.mainAttributes("Main-Class" : "com.botwave.analysis.LogAnalyzer")

repositories {
    mavenCentral()
}

dependencies {
    compile (
        'commons-codec:commons-codec:1.6',
        'commons-logging:commons-logging:1.1.1',
        'org.apache.httpcomponents:httpclient:4.2.1',
        'org.apache.httpcomponents:httpclient:4.2.1',
        'org.apache.httpcomponents:httpcore:4.2.1',
        'org.apache.httpcomponents:httpmime:4.2.1',
        'ch.qos.logback:logback-classic:1.0.6',
        'ch.qos.logback:logback-core:1.0.6',
        'org.slf4j:slf4j-api:1.6.0',
        'junit:junit:4.+'
    )
}

after i run : gradle build

it create the build folder, and i run the jar in build/libs/XXX.jar:

java -jar build/libs/XXX.jar

here is a execution says :

Exception in thread "main" java.lang.NoClassDefFoundError: ch/qos/logback/core/joran/spi/JoranException

how can i run it with the reference libraries?

Answer

erdi picture erdi · Feb 1, 2013

You can achieve it with Gradle application plugin