如何使用 Gradle 的 Manifest API 将“MANIFEST.MF”文件插入 zip 文件的根目录
我们使用 java 插件的 manifest
属性将 MANIFEST.MF
文件写入我们的 jar
工件。
我们还使用 gradle 构建 GWT
项目,并且我们为这些项目定义的输出是 zip
。我想在该 zip 文件的根目录中包含一个 MANIFEST.MF 文件。
我尝试使用 type: Jar
的任务,这样我就可以使用它的 manifest
属性,但问题当然是清单文件被写入 META-INF/MANIFEST.MF
,我不想要。原因是我们将存档解压缩到主应用程序中,并且我需要能够在运行时引用 MANIFEST.MF 文件以达到我自己的邪恶目的。
所以现在档案看起来像这样:
/gwtdirectory/
/gwtdirectory/file1
/gwtdirectory/file2
/gwtdirectory/...
/gwtdirectory/filen
我需要它像这样:
/gwtdirectory/
/gwtdirectory/MANIFEST.MF
/gwtdirectory/file1
/gwtdirectory/file2
/gwtdirectory/...
/gwtdirectory/filen
我已经成功地让它看起来像:
/gwtdirectory/
/gwtdirectory/META-INF/MANIFEST.MF
/gwtdirectory/file1
/gwtdirectory/file2
/gwtdirectory/...
/gwtdirectory/filen
通过这样的定义:
task pack(type: Jar){
manifest {
attributes(...)
}
extension = 'zip'
from gwt.destinationDir
}
writeTo
方法看起来很有前途,除了我找不到该接口的实现我可以使用它,但我试图避免自己编写。
想法?
We use the manifest
attribute of the java plugin to write MANIFEST.MF
files to our jar
artifacts.
We also use gradle to build GWT
projects and the output we've defined for those projects is a zip
. I'd like to include a MANIFEST.MF
file in the root of that zip file.
I've tried using a task of type: Jar
so I can use its manifest
property but the problem, of course, is that the manifest file is written into META-INF/MANIFEST.MF
, which I don't want. The reason is that we unzip the archive into the main app and I need to be able to reference the MANIFEST.MF
file at runtime for my own nefarious purposes.
So right now the archive looks like this:
/gwtdirectory/
/gwtdirectory/file1
/gwtdirectory/file2
/gwtdirectory/...
/gwtdirectory/filen
And I need it took like this:
/gwtdirectory/
/gwtdirectory/MANIFEST.MF
/gwtdirectory/file1
/gwtdirectory/file2
/gwtdirectory/...
/gwtdirectory/filen
I've already successfully gotten it to look like:
/gwtdirectory/
/gwtdirectory/META-INF/MANIFEST.MF
/gwtdirectory/file1
/gwtdirectory/file2
/gwtdirectory/...
/gwtdirectory/filen
Through a definition like:
task pack(type: Jar){
manifest {
attributes(...)
}
extension = 'zip'
from gwt.destinationDir
}
The writeTo
method looks mighty promising, except I can't find an implementation of that interface that I can use and I'm trying to avoid writing my own.
Thoughts?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
查看 Jar任务,看起来manifest文件的位置是不可配置的。
你可能想使用gradle自己的 DefaultManifest 实现来创建清单,然后将此文件与
from
一起包含在您的 zip 文件中。你可以试试这个:
Looking at the Jar task, it does not look like the location of the manifest file is configurable.
You may want to use gradle's own DefaultManifest implementation to create a manifest and then include this file with
from
in your zip file.You can try this:
我认为在 本章末尾正是您要寻找的内容< /a> 来自 Gradle 手册。
I think there is exactly what you are looking for at the end of this chapter from Gradle manual.