Joh*_*tch 7 java jar build gradle
我正在尝试使用ShadowJar插件创建两个'fatJars'作为同一构建文件的一部分.我试图通过声明两个ShadowJar类型的任务在构建内运行两次shadowJar任务
到目前为止,我已经定义了两个这样的任务:
task shadowjar_one (type: com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar)
task shadowjar_two (type: com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar)
Run Code Online (Sandbox Code Playgroud)
现在尝试像这样创建我的罐子:
shadowjar_one {
mergeServiceFiles()
exclude 'somefile.txt'
archiveName = 'jar1.jar'
appendManifest {
attributes 'Main-Class': 'some.package.someClass'
}
}
shadowjar_two {
mergeServiceFiles()
exclude 'someOtherfile.txt'
archiveName = 'jar2.jar'
appendManifest {
attributes 'Main-Class': 'some.package.someOtherClass'
}
}
Run Code Online (Sandbox Code Playgroud)
我面临的问题是创建了jar,但它们不包含来自"其他"jar的任何其他依赖项(包,文件等).jar只包含META-INF和当前项目的包目录.
知道可能是什么问题吗?
注意:我期待生成两个略有不同的jar文件.两者必须具有相同的项目代码库,并且清单的Main-Class属性存在差异(以及其他一些小差异)
非常感谢!
作者在这里给出了一个很好的解决方案(因为它既简短又有效):
https://github.com/johnrengelman/shadow/issues/108
我实际上正在对该解决方案进行调整,出现在该页面的底部(我添加了一些说明以作解释):
task bootstrapNodeJar(type: ShadowJar) {
group = "shadow" // Not a must have, but it's always good to have a group, you can chose whichever - this is the one shadowJar belongs to
description = "Builds a Bitsquare bootstrap node executable jar" // Same as the above
manifest.attributes 'Main-Class': 'io.bitsquare.app.cli.BootstrapNodeMain' // The main attraction! Be sure to update this line
classifier = 'bootstrapNode' // General jar task property - see more about it in the Gradle manual
from(project.convention.getPlugin(JavaPluginConvention).sourceSets.main.output) // Leave as is
configurations = [project.configurations.runtime] // Same as the above
exclude('META-INF/INDEX.LIST', 'META-INF/*.SF', 'META-INF/*.DSA', 'META-INF/*.RSA') // This one is actually really important!
// Here you can add other Jar properties like destinationDir, for example
}
Run Code Online (Sandbox Code Playgroud)
Shadow 插件作者在这里 - 我刚刚在这里意识到这个问题。shadowJar您遇到的是 Shadow 插件使用一组为该任务定义的约定创建和配置任务的事实。
当您使用该类型创建自己的任务时,您需要手动定义许多配置选项,因为插件无法知道您对这些任务的意图。
您可以在此处引用应用于内置任务的配置: https: //github.com/johnrengelman/shadow/blob/master/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/ ShadowJavaPlugin.groovy#L38-L63
| 归档时间: |
|
| 查看次数: |
3119 次 |
| 最近记录: |