[英]How do I make gradle's build task generate the shadow jar _instead_ of the “regular” jar?
(這是使用gradle 2.4)
對於我的一個項目,分成幾個子模塊,我使用的shadow插件非常適合我的需要; 它有一個main,並且根據插件的README的推薦,我使用應用程序插件與它一起使用,以便在清單中生成Main-Class,一切正常。
現在,這是一個SonarQube插件項目,我也使用(成功!) gradle聲納packagin插件 。 這個插件的作用是,當你./gradlew build
,生成聲納插件而不是“常規”jar。
我希望在這里為我的子項目做同樣的事情,除了我希望它只生成影子jar插件而不是“常規”插件...現在我使用這個簡單的文件生成兩個:
buildscript {
repositories {
jcenter();
}
dependencies {
classpath(group: "com.github.jengelman.gradle.plugins",
name:"shadow", version:"1.2.1");
}
}
apply(plugin: "application");
apply(plugin: "com.github.johnrengelman.shadow");
dependencies {
// whatever
}
mainClassName = //whatever
artifacts {
shadowJar;
}
// Here is the hack...
build.dependsOn(shadowJar);
如何修改此文件以便僅生成陰影jar而不是常規jar?
您可以通過將以下行添加到gradle腳本來禁用jar任務:
// Disable the 'jar' task
jar.enabled = false
因此,在執行gradle腳本時,它將顯示
:罐子SKIPPED
如果您希望配置所有子項目,則可以將以下內容添加到根build.gradle中
subprojects {
// Disable the 'jar' task
tasks.jar.enabled = false
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.