我正在尝试创建两个'fatJars‘使用ShadowJar插件作为同一构建文件的一部分。通过声明两个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)现在试着这样创建我的jars:
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'
}
}我面临的问题是,jars是创建的,但它们不包含来自“其他”jars的任何其他依赖项(包、文件等)。jars只包含META-INF和当前项目的包目录。
你知道问题出在哪里吗?
注意:我期望生成两个略有不同的jar文件。两者必须具有相同的项目代码库,但在manifest的Main-Class属性中存在差异(以及其他一些小差异)
非常感谢!
发布于 2016-06-16 18:47:06
作者在这里给出了一个非常好的解决方案(因为它既简短又有效):
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
}发布于 2015-05-14 23:44:24
影子插件的作者在这里-我刚刚意识到这个问题。您遇到的事实是,影子插件使用一组为该任务定义的约定来创建和配置shadowJar任务。
当您使用该类型创建您自己的任务时,您将需要手动定义许多这样的配置选项,因为插件无法知道您对这些任务的意图。
您可以在此处引用正在应用于内置任务的配置:https://github.com/johnrengelman/shadow/blob/master/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/ShadowJavaPlugin.groovy#L38-L63
发布于 2015-05-19 17:17:00
一个workaround that I've used应该只有一个shadowJar任务,但是要传递参数。在您的示例中,如下所示:
shadowJar {
mergeServiceFiles()
exclude System.properties.getProperty('exclude')
archiveName = System.properties.getProperty('archiveName')
appendManifest {
attributes 'Main-Class': System.properties.getProperty('mainClass')
}
}然后,在启动应用程序时:
gradlew shadowJar -Dexclude=... -DarchiveName=... -DmainClass=...https://stackoverflow.com/questions/25309250
复制相似问题