I am using the Eclipse IDE, using Kryonet and LibGDX libraries.
I am currently trying to make a fat jar file - making kryonet a dependency.
How would I make a big jar file?
Here is my build.gradle file
sourceCompatibility = 1.7
sourceSets.main.java.srcDirs = [ "src/" ]
sourceSets.main.resources.srcDirs = ["../core/assets"]
project.ext.mainClassName = "uk.ac.aston.teamproj.game.desktop.DesktopLauncher"
project.ext.assetsDir = new File("../core/assets")
task run(dependsOn: classes, type: JavaExec) {
main = project.mainClassName
classpath = sourceSets.main.runtimeClasspath
standardInput = System.in
workingDir = project.assetsDir
ignoreExitValue = true
}
task debug(dependsOn: classes, type: JavaExec) {
main = project.mainClassName
classpath = sourceSets.main.runtimeClasspath
standardInput = System.in
workingDir = project.assetsDir
ignoreExitValue = true
debug = true
}
task dist(type: Jar) {
manifest {
attributes 'Main-Class': project.mainClassName
}
dependsOn configurations.runtimeClasspath
from {
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
}
with jar
}
dist.dependsOn classes
eclipse.project.name = appName + "-desktop"
Sounds like you could use the "Shadow" gradle plugin to make fat jars, it makes the process a lot simpler.
You can find detailed instructions on how to use it here
If you want an executable jar don't forget to specify the MainClass attribute. Here's an example of usage:
This will add the following to your build:
shadowJartask to the project.shadowconfiguration to the project.shadowJartask to include all sources from the project's main sourceSet.shadowJartask to bundle all dependencies from theruntimeClasspathconfiguration.classifierattribute of theshadowJartask to be 'all' .shadowJartask to generate a Manifest with:Class-Pathattribute to theManifestthat appendsall dependenciesfrom the shadow configurationThe
shadowJartask will build the fat jar, optionally it will be executable if you specified a Main-Class attribute for the manifest in thejarconfiguration, as I did in the above example.