我试图用一个 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"
}
Run Code Online (Sandbox Code Playgroud)
谢谢
您不需要配置同一个 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)
Run Code Online (Sandbox Code Playgroud)
有关配置选项的详细信息,请参阅Gradle 构建语言参考。
| 归档时间: |
|
| 查看次数: |
4130 次 |
| 最近记录: |