Wednesday, April 24, 2013

create a fat jar in gradle

How to create a fat jar in a gradle build:

// this task builds a fat jar which includes the runtime dependencies in the jar
jar {
   dependsOn configurations.runtime
   from {
      configurations.runtime.collect { it.isDirectory() ? it : zipTree(it) }
   }
   exclude 'META-INF/*.DSA', 'META-INF/*.RSA', 'META-INF/*.SF'
   manifest {
      attributes('Main-Class': 'com.example.MainClass')
   }
}

Class-Path is also a valid manifest attribute, and '.' can be its value to specify the current directory to find other jars to search. This allows to use other jar files since the classpath

No comments:

Post a Comment