使用 Gradle 在清单中添加类路径 [英] Add classpath in manifest using Gradle
本文介绍了使用 Gradle 在清单中添加类路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我希望我的 Gradle 构建脚本将完整的类路径添加到构建后创建的 JAR 文件中包含的清单文件中.
I would like my Gradle build script to add the complete Classpath to the manifest file contained in JAR file created after the build.
示例:
Manifest-Version: 1.0
Class-Path: MyProject.jar SomeLibrary.jar AnotherLib.jar
我的构建脚本已经通过这种方式向清单添加了一些信息:
My build script already add some information to the manifest this way:
jar {
manifest {
attributes("Implementation-Title": project.name,
"Implementation-Version": version,
"Main-Class": mainClassName,
}
}
如何获取要添加到清单中的依赖项列表?
How do I get the list of dependencies to add to the manifest?
Java 教程的这个页面更详细地描述了如何以及为什么将类路径添加到清单:将类添加到 JAR 文件的类路径
This page of Java tutorials describes more in detail how and why adding classpath to the manifest: Adding Classes to the JAR File's Classpath
推荐答案
在 Gradle 的论坛上找到了解决方案:
Found a solution on Gradle's forum:
jar {
manifest {
attributes(
"Class-Path": configurations.compile.collect { it.getName() }.join(' '))
}
}
这篇关于使用 Gradle 在清单中添加类路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文