我试图用一个 build.gradle 创建两个单独的 jar 文件。
它几乎可以工作,但一个会覆盖另一个。正确的做法是什么?
jar {
//include contents of output dir
from "$buildDir/classes/main"
exclude '**/a1/**'
archiveName "X1-1.0.0.jar"
}
jar {
//include contents of output dir
from "$buildDir/classes/main"
exclude '**/a2/**'
archiveName "X2-1.0.0.jar"
}
谢谢
最佳答案
您需要使用两个 Jar 任务,而不是两次配置相同的 Jar 任务。假设您使用的是 java
插件,您可以重用该插件添加的名为 jar
的 Jar 任务,并自行添加另一个:
// reconfigure the Java plugin's `jar` task
jar {
exclude '**/a1/**'
baseName = 'X1'
}
// need to configure this one from scratch
task x2jar(type: Jar) {
// referring to the output in this way
// allows Gradle to infer task dependencies automatically
from sourceSets.main.output
exclude '**/a2/**'
baseName = 'X2'
}
// one way to make `gradle build` run both Jar tasks
assemble.dependsOn(x2jar)
有关配置选项的详细信息,请参阅 Gradle Build Language Reference .
关于java - 如何使用单个 build.gradle 创建两个单独的 jar 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20389554/