java 如何让 gradle 的构建任务生成阴影 jar _而不是“常规”jar?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30309290/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I make gradle's build task generate the shadow jar _instead_ of the "regular" jar?
提问by fge
(this is using gradle 2.4)
(这是使用 gradle 2.4)
For one of my projects, split into several submodules, I use the shadow pluginwhich works very well for my needs; it has a main, and as recommended by the plugin's README, I use the application plugin in conjuction with it so that the Main-Class is generated in the manifest, all works well.
对于我的一个项目,分成几个子模块,我使用shadow 插件,它非常适合我的需求;它有一个主要的,并且根据插件的自述文件的建议,我将应用程序插件与它结合使用,以便在清单中生成 Main-Class,一切正常。
Now, this is a SonarQube plugin project, and I also use (successfully!) the gradle sonar packagin plugin. And what this plugin does is, when you ./gradlew build
, generate the sonar plugin instead of the "regular" jar.
现在,这是一个 SonarQube 插件项目,我也使用(成功!)gradle sonar packagin plugin。这个插件的作用是,当您./gradlew build
生成声纳插件而不是“常规”jar 时。
I wish to do the same for my subproject here, except that I want it to generate only the shadow jar plugin instead of the "regular" plugin... Right now I generate both using this simple file:
我希望在这里为我的子项目做同样的事情,除了我希望它只生成 shadow 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);
How do I modify this file so that only the shadow jar is generated and not the regular jar?
如何修改此文件,以便仅生成 shadow jar 而不是常规 jar?
回答by MJSG
You could disable the jar task by adding the following lines to your gradle script:
您可以通过将以下几行添加到您的 gradle 脚本来禁用 jar 任务:
// Disable the 'jar' task
jar.enabled = false
So, when executing the gradle script, it will show
所以,当执行 gradle 脚本时,它会显示
:jar SKIPPED
:jar 跳过
If you wish to configure all sub-projects, then you can add the following into your root build.gradle
如果你想配置所有子项目,那么你可以将以下内容添加到你的根 build.gradle 中
subprojects {
// Disable the 'jar' task
tasks.jar.enabled = false
}