Dependencies not showing up in jar with Gradle?

一世执手 提交于 2019-12-10 23:14:54

问题


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/**")
}

回答1:


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.



来源:https://stackoverflow.com/questions/34240598/dependencies-not-showing-up-in-jar-with-gradle

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!