Tuesday, July 16, 2013

Gradle fat jar script

Sample Gradle build script to create a executable jar:

apply plugin: 'java'
apply plugin: 'application'
// Set our project variables
project.ext {
    dropwizardVersion = '0.6.2'
}
// The main class of the application
mainClassName = 'nl.jworks.epub.dropwizard.HelloWorldService'
dependencies {
    compile project(":epub-organizer-core")
    compile (
            'com.yammer.dropwizard:dropwizard-core:' + dropwizardVersion,
            'com.yammer.dropwizard:dropwizard-hibernate:' + dropwizardVersion,
            'com.yammer.dropwizard:dropwizard-migrations:' + dropwizardVersion,
            'com.yammer.dropwizard:dropwizard-auth:' + dropwizardVersion,
            'com.h2database:h2:1.3.168'
    )
}
// Configure the run task to start the Dropwizard service
run {
    args 'server', './src/main/resources/hello-world.yml'
}
// Create the executable jar and exclude some certificates
jar {
    manifest {
        attributes "Implementation-Title": "Gradle Quickstart"
        attributes "Implementation-Version": version
        attributes "Main-Class" : mainClassName
    }
    // remove the security files (from mail.jar / activation.jar) so that the jar will be executable.
    doFirst {
        from (configurations.runtime.resolve().collect { it.isDirectory() ? it : zipTree(it) }) {
            exclude 'META-INF/MANIFEST.MF'
            exclude 'META-INF/*.SF'
            exclude 'META-INF/*.DSA'
            exclude 'META-INF/*.RSA'
        }
    }
}

No comments:

Post a Comment