我同意与接受的答案太本金。 我发现一个项目,其中客户端需要两个JAR基本上是相同的文件,但Manifest仅通过Class-Path键不同。
jar {
manifest {
attributes(
"Main-Class": platformMainClass,
"Implementation-Title": platformDisplayName,
"Implementation-Description": platformDescription,
"Platform-Version": platformVersion,
"Implementation-Version": version,
"Build-Assembly-User": System.getProperty("user.name"),
"Build-Assembly-Date": new java.util.Date().toString(),
"Class-Path": configurations.compile.collect { "lib/"+it.getName() }.join(' ')
)
}
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
exclude([ 'log4j*.properties', 'uk/gov/acme/secret/product/server/**' ])
}
同样的清单,然后将源代码是:
task applicationClientJar(type: Jar, description: "Creates the Application Client JAR file.") {
dependsOn compileJava
manifest {
attributes(
"Main-Class": platformMainClass,
"Implementation-Title": platformDisplayName,
"Implementation-Description": platformDescription,
"Platform-Version": platformVersion,
"Implementation-Version": version,
"Assembly-Date": new java.util.Date().toString()
)
}
archiveName = "acme-client-${platformVersion}.jar"
destinationDir = file("${buildDir}/libs")
from sourceSets.main.output
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
exclude([ 'log4j*.properties', 'uk/gov/acme/secret/product/server/**' }
所以格热戈日表示法是正确的,因为摇篮应该知道有两种不同的JAR与GAVs。多模块是首选。
compile "uk.gov.acme.secret:acme:1.0" // CORE
compile "uk.gov.acme.secret:acme-client:1.0"
来配置这个问题的唯一方法是使用多模块式摇篮项目,然后添加一个编译和/或部署依赖于核心/主项目。
project(':common:acme-micro-service-webapp') {
dependencies {
compile project(':common:acme-core')
}
}
在'acme-micro-service-webapp'项目中,这确保首先编译从属'common:acme-core'。 PS:我仍在试图找出更好的解决方案。
PS PS:如果您使用的是Maven,也可以勾选`install'任务。
这很好,但是您如何引用其他项目的单独'.jar'文件 - 例如你怎么能把'client.jar'放到另一个子项目中呢? – z0r
@z0r我们只是将工件发布到存储库,然后将它们用作子项目中的依赖关系。 P.S.对于延迟回复抱歉。 – vitalidze