Gradle中没有出现与jar相关的依赖项? [英] Dependencies not showing up in jar with Gradle?

查看:349
本文介绍了Gradle中没有出现与jar相关的依赖项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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





<$ p $应用插件:'java'
apply plugin:'eclipse'

//在源项目集中指定源目录
sourceSets {
main {
java.srcDir($ {projectDir} / src /)
resources.srcDir($ {projectDir} / src /)
}
}

//项目的依赖项存储在libs目录中
dependencies {
compile fileTree(dir:'libs',include:['* .jar'])
}

//控制进入JAR的内容
jar {

manifest {
attributes'Main-Class':'com .elsea.sublimelauncher.Driver'
}

//包含除测试以外的所有类
include(com / elsea / sublimelauncher / **)
}


jar 任务从项目源文件中生成一个可执行的jar文件。它不会包含您的程序所需的任何传递库。这对Web服务器来说很好,因为它们通常将所有的jar放在一个特殊的lib文件夹中,但对许多独立的程序来说并不是很好。

你想要做的是创建一个胖的jar包,它将包含单个jar文件中的所有类和资源。
如果你使用Maven,你可以看到像'my-program-v1.0-jar-with-dependcies.jar'这样的文件。



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


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.

这篇关于Gradle中没有出现与jar相关的依赖项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆