Is there a maven shade plugin equivalent in gradle?


I need to create a fat jar but also need to relocate the included classes from the jars in order to create a private copy of their bytecode in gradle and was wondering if this is possible at all at the moment, Maven supports this through the Shade plugin ( which does this pretty well.

Is there a solution for this in Gradle?



You can use the JarJar ant task after creating the jar using the fatJar plugin.

configurations {
  dependencies {
  tools "org.elasticsearch:es-jarjar:1.0.0"
jar << {
  jarjarArchivePath = new File(jar.archivePath.absolutePath + ".jarjar.jar")
  project.ant {
    taskdef name: "jarjar", classname: "com.tonicsystems.jarjar.JarJarTask", classpath:
    jarjar(jarfile: jarjarArchivePath, filesetmanifest: "merge", manifest:"src/main/resources/MANIFEST.MF") {
      zipfileset(src: jar.archivePath)
      configurations.runtime.files.findAll {file ->
        ['gson'].any { }
        rule pattern: "**", result: "com.foobar.repacked.gson.@1"
    delete(file: jar.archivePath)
    copy(file: jarjarArchivePath, tofile: jar.archivePath)
    delete(file: jarjarArchivePath)

You can check out the new Shadow plugin:

Or on Github:

Does this work without farJar?