![](/img/trans.png)
[英]Generating an executable .jar with dependencies (external jars) in Eclipse
[英]How to generate a jar with internal dependencies bundled and external dependencies as external jars?
我有一个Gradle项目,它取决于子项目。 我想创建一个包含所有子项目的“胖罐子”,以及作为外部罐子的外部依赖项。
的build.gradle:
dependencies {
compile project(':MyDep1')
compile project(':MyDep2')
compile 'com.google.guava:guava:18.0'
}
我希望能够生成以下输出:
MyProject.jar
- >包括MyDep1和MyDep2
libs/guavaXXX.jar
- > Guava作为外部lib
我不知道怎么做到这一点。
使用不同的配置来保存内部和外部依赖关系,并将其中一个配置打包到项目工件中。
configurations{
internalCompile
externalCompile
}
//add both int and ext to compile
configurations.compile.extendsFrom(internalCompile)
configurations.compile.extendsFrom(externalCompile)
dependencies{
internalCompile project(':MyDep1')
internalCompile project(':MyDep2')
externalCompile 'com.google.guava:guava:18.0'
}
在你的胖jar任务中,只包含来自internalCompile
我终于使用了这个解决方案:
jar {
subprojects.each {
from files(it.sourceSets.main.output)
}
}
distributions {
main {
contents {
exclude subprojects.jar.archivePath.name
}
}
}
在我的项目的jar中,我包含了所有子项目输出的内容。 在分发中,我从子项目中排除了jar(因此它只包含依赖项)。 这可能不是最好的方法,但它很简单并且有效。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.