Dropwizard Gradle Build with ShadowJar

I’ve moved from FatJar to ShadowJar plugin for building my Dropwizard Gradle fat jar. It’s a direct port of the Maven Shade plugin, under active support by the folks at Object Partners and offers better performance.

Setting up Shade is quite straight forward, simply put in the following configurations:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.github.jengelman.gradle.plugins:shadow:1.1.2'
    }
}
apply plugin: 'com.github.johnrengelman.shadow'

and configure your shadow plugin with the ‘shadow’ and ‘jar’ keyword:

shadow {
    exclude 'META-INF/*.DSA'
    exclude 'META-INF/*.RSA'
}
jar {
    manifest {
        attributes 'Main-Class': mainClassName
    }
}

Everything builts correctly but I get the following error when I try to run my Dropwizard application:

yun$ java -jar build/distributions/dropwizard-example-xml-0.5.0-SNAPSHOT.jar server helloxml.yml
helloxml.yml has an error:
  * Failed to parse configuration at: server.connector; Could not resolve type id 'http' into a subtype of [simple type, class io.dropwizard.jetty.ConnectorFactory]

The answer can be found on Dropwizard Google Groups. Simply need to add the following Shadow plugin into my shadow configuraiton:

shadow {
    mergeServiceFiles()
    exclude 'META-INF/*.DSA'
    exclude 'META-INF/*.RSA'
}

A example of how all these fit together in gradle can be found in my Dropwizard XML Example project. Or you can refer to the following gist:

yunspace

Read more posts by this author.

Sydney, Australia https://www.yunspace.com