java - 如何在 Gradle 生成的 jar 中生成 INDEX.LIST 文件?
问题描述
我正在将现有的 Ant 构建移动到 Gradle,并试图确保新构建生成的工件与旧构建相同。
一个现有的子项目根据以下内容生成一个带有INDEX.LIST
文件的 jar:
https ://docs.oracle.com/javase/8/docs/technotes/guides/jar/jar.html#JAR_Index
我想让 Gradle Jar 任务将此文件包含在其输出中,但似乎找不到任何内置方法来执行此操作。到目前为止,我为在我的根项目中启用此功能而构建的是:
allprojects { project ->
/**
* If we want to generate jars with META-INF/INDEX.LIST existing and populated, Gradle's jar task
* will NOT do this by default. So, at the END of running
* a jar task, we can then call Ant's jar task, which allows for UPDATING an existing jar using
* the index = true attribute argument, which will create that file with appropriate contents.
*
* This bit of code here will write a self-configuring method to every Jar task in the project which can do this.
*
* To make a Jar task use this option, do:
*
* <code>
* jar {
* withIndex()
* }
* </code>
*/
tasks.withType(Jar) { task ->
task.ext.withIndex = {
doLast {
ant.jar(update: true, index: true, destfile: task.getArchiveFile().get().asFile.path)
}
}
}
}
这似乎工作正常。
我是否错过了更好的(内置)方法来做到这一点?
解决方案
推荐阅读
- sql-server - 使用来自 OLAP 的 OPENQUERY 转换失败
- python - openpyxl library StopIteration error when opening xlsx file
- machine-learning - 在命名实体识别任务中,条件随机场是双向的吗?
- reactjs - 如何在 ReactTable 中设置自定义过滤?
- python - 字符串到字典,键是以“。”结尾的单词。
- php - 如何将 1 添加到我的数据库中的“kijkers”表中。它用于计算网站被访问的次数
- powershell - 我想使用 powershell 将时间和日期列添加到 csv 文件
- ruby - 如何解决 Twitter API 的速率限制超出问题
- axon - org.axonframework.serialization.UnknownSerializedTypeException(无法反序列化消息。序列化类型未知:
- excel - 单元格中的箭头方向与excel中的另一个单元格相匹配