依赖关系没有显示在Gradle的jar中吗?

Con*_*sea 2 java dependencies gradle build.gradle

我正在使用这个build.grade。当我运行时gradlew build,它仅使用源而不是libs文件夹中的stone.jar生成jar文件。我应该怎么做?

在此处输入图片说明

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/**")
}
Run Code Online (Sandbox Code Playgroud)

Ada*_*ker 6

默认情况下,jargradle中的任务会从项目源文件中构建可执行的jar文件。它不会包含程序需要的任何传递库。这对Web服务器很有用,因为它们通常将所有jar放在一个特殊的lib文件夹中,但对许多独立程序却不利。

您要做的是创建一个胖jar,它将在一个jar文件中包含所有类和资源。如果您使用了Maven,则可以看到类似“ my-program-v1.0-jar-with-dependcies.jar”的文件

有一个gradle 的影子插件可以做同样的事情。github上的Wiki包含有关如何在项目中使用它的所有信息。