Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dependencies not showing up in jar with Gradle?

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?

enter image description here

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/**")
}
like image 889
Connorelsea Avatar asked Dec 06 '25 15:12

Connorelsea


1 Answers

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.

like image 97
AdamSkywalker Avatar answered Dec 08 '25 05:12

AdamSkywalker



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!