Java 如何使用 Maven 将实现版本值添加到 jar 清单?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/921667/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 21:07:11  来源:igfitidea点击:

How do I add an Implementation-Version value to a jar manifest using Maven?

javamaven-2build-processjarmanifest

提问by izb

I'd like to add an Implementation-Version line to a manifest in my jar file that reflects the POM version number. I can't for the life of me work out how to do this using the jar plugin.

我想在反映 POM 版本号的 jar 文件中的清单中添加一个 Implementation-Version 行。我一生都无法使用 jar 插件来解决这个问题。

Is this possible?

这可能吗?

采纳答案by Ascalonian

You would use the Maven Archiver:

您将使用 Maven Archiver:

<plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-jar-plugin</artifactId>
      <configuration>
        <archive>
          <manifest>
            <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
          </manifest>
        </archive>
      </configuration>
    </plugin>
  </plugins>

This will add the following to the manifest file:

这会将以下内容添加到清单文件中:

Implementation-Title: ${pom.name}
Implementation-Version: ${pom.version}
Implementation-Vendor-Id: ${pom.groupId}
Implementation-Vendor: ${pom.organization.name}