【发布时间】:2021-05-25 18:02:33
【问题描述】:
我需要什么
我们使用 Gradle 和 shadowJar 打包我们的产品。我们使用的一些库,使用individual sections in Jar Manifests,特别是诸如 Implementation-Title 和 实施版本。这些有时会显示在我们的产品(输出)中,所以我希望它们能够在 shawdowJar-Process 中存活下来。
示例
lib1.jar/META-INF/MANIFEST.MF
Manifest-Version: 1.0
...
Name: org/some/lib
...
Implementation-Title: someLib
Implementation-Version: 2.3
...
lib2.jar/META-INF/MANIFEST.MF
Manifest-Version: 1.0
...
Name: org/some/other/lib
...
Implementation-Title: someOtherLib
Implementation-Version: 5.7-RC
...
=> product.jar/META-INF/MANIFEST.MF
Manifest-Version: 1.0
...
Name: org/some/lib
...
Implementation-Title: someLib
Implementation-Version: 2.3
...
Name: org/some/other/lib
...
Implementation-Title: someOtherLib
Implementation-Version: 5.7-RC
...
我发现了什么
- manipulate the resulting Manifest 使用 shadowJar 相当容易:
project.shadowJar {
manifest {
attributes(["Implementation-Title" : "someLib"], "org/some/lib")
attributes(["Implementation-Title" : "someOtherLib"], "org/some/other/lib")
}
}
静态生成我想要的。
- shadowJar 可以为我提供a list of dependencies。但是,当我像这样遍历 FileCollection 时
project.shadowJar {
manifest {
for (dependency in includedDependencies) {
// read in jar file and set attributes
}
}
}
Gradle 不高兴:“在依赖解析中包含依赖配置 ':project:products:
- 当我定义一个新任务时
def dependencies = [];
project.tasks.register('resolveDependencies') {
doFirst {
gradleProject.configurations.compile.resolvedConfiguration.resolvedArtifacts.each {
dependencies.add(it.file)
}
}
}
project.tasks['shadowJar'].dependsOn(project.tasks['resolveDependencies']);
project.shadowJar {
manifest {
// dependencies will be empty when this code is called
for (dependency in dependencies) {
// read in jar file and set attributes
}
}
}
依赖没有及时解决。
我想知道的
如何在不影响 Gradle 的情况下访问依赖项?或者,是否有另一种方法可以将命名的各个部分与 shadowJar 合并?
【问题讨论】:
标签: gradle manifest.mf gradle-dependencies shadowjar