I am using this build.grade. When I run gradlew build
, it generates a jar file only with the source, not the stone.jar in the libs folder. How should I be doing this?
apply plugin: 'java'
apply plugin: 'eclipse'
// Source sets in the project, specify source directories
sourceSets {
main {
java.srcDir("${projectDir}/src/")
resources.srcDir("${projectDir}/src/")
}
}
// Dependencies for the project are stored in the libs directory
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
}
// Control what goes into the JAR
jar {
manifest {
attributes 'Main-Class': 'com.elsea.sublimelauncher.Driver'
}
// Include all the classes except the tests
include("com/elsea/sublimelauncher/**")
}
By default,
jar
task in gradle builds an executable jar file from your project source files. It will not contain any transitive libs that are needed for your program. It is good for web servers, because they usually keep all jars in a special lib folder, but is not good for many standalone programs.What you want to do is to create a fat jar, that will contain all classes and resources in a single jar file. If you used Maven you could see files like 'my-program-v1.0-jar-with-dependcies.jar'
There is a shadow plugin for gradle that can do the same thing. Wiki on github contains all the information about how to use it in your project.