【发布时间】:2015-08-24 01:06:46
【问题描述】:
我正在尝试在多项目 Gradle 构建中创建一个胖 jar 文件,如下所示:
root
+-- project1
+-- project2
project1 提供了基本功能,然后 project2 使用它来创建可执行的 jar。可执行 JAR 需要包含依赖项中的所有代码,以便它可以独立运行。
对于外部依赖,这很好用。在 project2 中,我创建了一个新配置:
apply plugin: 'maven'
apply plugin: 'java'
configurations {
// configuration for JARs that need to be included in the final packaging
includeInJar
}
然后添加依赖:
dependencies {
includeInJar 'com.fasterxml.jackson.core:jackson-databind:2.2.3'
...
configurations.compile.extendsFrom(configurations.includeInJar)
}
包装看起来像这样:
jar {
manifest {
attributes "Main-Class": "com.acme.project1.MyTest"
}
// import all dependencies into the Jar so that it can be run easily
from {
configurations.includeInJar.collect {
it.isDirectory() ? it : zipTree(it)
}
}
}
jar 是使用来自外部依赖项的所有文件正确构建的。问题在于项目对 project1 的依赖:
includeInJar project(':project1')
当它存在时,当它尝试组装 JAR 时出现错误,它在 project1 build/libs 目录中找不到 jar(例如 project1-0.4.0.jar),因为它不存在。该消息是正确的,因为 project1 构建了一个 SNAPSHOT jar(例如 project1-0.4.0-SNAPSHOT.jar)。
问题是,为什么项目在构建SNAPSHOT jars的时候,配置会引用非SNAPSHOT jars?我可以更改哪些内容才能找到正确的 jar?
【问题讨论】:
标签: jar gradle dependencies