我也原则上同意接受的答案。
我发现了一个项目,其中客户端需要两个 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/**' }
所以 Grzegorz 表示法是正确的,因为 Gradle 应该知道 GAV 有两个不同的 JAR。多模块是首选。
compile "uk.gov.acme.secret:acme:1.0" // CORE
compile "uk.gov.acme.secret:acme-client:1.0"
为此配置的唯一方法是使用 Multi-Module Gradle 项目,然后将编译和/或部署依赖项添加到核心/主项目。
project(':common:acme-micro-service-webapp') {
dependencies {
compile project(':common:acme-core')
}
}
在“acme-micro-service-webapp”项目中,这确保了依赖的“common:acme-core”首先被编译。
PS:我还在努力寻找更好的解决方案。
PS PS:如果您也使用 Maven,可能会挂上“安装”任务。