使用Gradle在清单中添加类路径 [英] Add classpath in manifest using Gradle

查看:714
本文介绍了使用Gradle在清单中添加类路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望我的Gradle构建脚本将完整的Classpath添加到构建后创建的JAR文件中包含的清单文件中。


$ b

b
$ b

  Manifest-Version:1.0 
Class-Path:MyProject.jar SomeLibrary.jar AnotherLib.jar
> jar {
manifest {
attributes(Implementation-Title:project.name,
Implementation-Version:version,
Main- Class:mainClassName,
}
}

如何获取列表依赖关系添加到清单中?






这个Java教程页面详细描述了如何以及为什么将classpath添加到清单:将类添加到JAR文件的类路径

  jar {$ b 

在Gradle论坛上找到了解决方案: $ b manifest {
attributes(
Class-Path:configurations.compile.collect {it.getName()} .join(''))
}
}

来源:在子项目的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.

Example:

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?


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

解决方案

Found a solution on Gradle's forum:

jar {
  manifest {
    attributes(
      "Class-Path": configurations.compile.collect { it.getName() }.join(' '))
  }
}

Source: Manifest with Classpath in Jar Task for Subprojects

这篇关于使用Gradle在清单中添加类路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆