Home > Enterprise >  How can i build a FatJar with gradle (Without the depricated functions)
How can i build a FatJar with gradle (Without the depricated functions)

Time:11-14

I am trying to create a FatJar with local .jar's. However, I have only found tutorials and guides in which the described methods like "compile" are deprecated.

What is the newest and best way to do something like this?

Need the finished .jar (with all depenecies) to run it on a remote server.

CodePudding user response:

Am assuming your not using kotlin because you did not mentioned any related info . You can create your own task to do so

task createfatJar(type: Jar) {
  manifest {
    attributes 'Main-Class': 'full.package.path.Main'
  }
  archiveClassifier = "all"
  from {
    configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
    configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
    }
  with jar
}

if your using the latest version , probably 7 you need to add duplicatesStrategy 'exclude' and remove the configurations.compile.collect

Am using 6.9 but it should look like the following

task createfatJar(type: Jar) {
  duplicatesStrategy 'exclude'
  manifest {
    attributes 'Main-Class': 'full.package.path.Main'
  }
  archiveClassifier = "all"
  from {
    configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
    }
  with jar
}

Hope this work if your using version 7 and higher .

  • Related