在 Java jar 清单中嵌入 SVN 版本号的最佳实践?

发布于 2024-12-28 01:48:47 字数 335 浏览 6 评论 0原文

我看到类似 如何使用 maven 从 subversion 获取修订号? 但是对于清单中使用的实际字段、版本 # 和存储库 URL(即显示它位于主干还是分支),是否有任何标准(事实上或其他)?我已经看到使用了实现版本,有或没有前导“r”(用于修订),我也看到了实现构建:也被使用。

编辑 我删除了 Maven 标签,它不应该在那里。我的问题是关于 jar 内容,而不是工具本身。

I see questions like How to get revision number from subversion using maven? but are there any standards (defacto or otherwise) for which actual fields to use in the manifest, for the version # and for the repository URL (i.e., showing that it's on the trunk vs. a branch)? I've seen Implementation-Version used, with and without a leading "r" (for revision), I've seen Implementation-Build: used as well.

edit I removed the maven tag, that shouldn't have been there. My question is about the jar contents, not the tooling per se.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

旧情别恋 2025-01-04 01:48:47

不幸的是,jar 清单本身没有任何版本编号标准。

但实际上,还有另一种标准方法可以自动更新修订号。您可以使用 svn:keywords为了在每次提交后获取文件中的当前修订号。有用于修订替换的 $Revision$ 属性和用于存储库 URL 替换的 $HeadURL$ 属性。您只需将以下字符串放入文件中并将该文件置于版本控制之下:

$Revision$ $HeadURL$

如果您使用 Maven 动态创建清单,我建议将以下内容放入 version.properties 文件中:

revision=$Revision$
repourl=$HeadURL$

然后包含在使用以下语句进入 pom.xml (maven 应该启用属性插件):

<plugins>
  <plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>properties-maven-plugin</artifactId>
    <version>1.0-alpha-1</version>
    <executions>
      <execution>
        <phase>initialize</phase>
        <goals>
          <goal>read-project-properties</goal>
        </goals>
        <configuration>
          <files>
            <file>version.properties</file>
          </files>
        </configuration>
      </execution>
    </executions>
  </plugin>

然后您将能够将修订号和存储库 URL 添加到清单中:

<manifest>
  <attribute name="Revision" value="${revision}" />
  <attribute name="Repository URL" value="${repourl}" />
</manifest>

另请注意,您将需要 使用 subversion 属性显式启用 svn:keywords 以获得$Revision$$HeadURL$ 在文件中替换为实际值。如果您决定使用 version.properties,您将需要运行以下命令:

svn propset svn:keywords Revision version.properties
svn propset svn:keywords HeadURL version.properties

Unfortunately, jar manifests by itself do not have any standard for version numbering.

But, actually, there is another standard way of getting revision number updated automatically. You could use svn:keywords in order to get current revision number in your files after each commit. There is $Revision$ property for revision substitution and $HeadURL$ for repository URL substitution. You just need to put following string into the file and place this file under version control:

$Revision$ $HeadURL$

If you create manifest on the fly with maven, I would recommend putting following content into version.properties file:

revision=$Revision$
repourl=$HeadURL$

Then include in into pom.xml with the statement (maven should have properties plugin enabled):

<plugins>
  <plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>properties-maven-plugin</artifactId>
    <version>1.0-alpha-1</version>
    <executions>
      <execution>
        <phase>initialize</phase>
        <goals>
          <goal>read-project-properties</goal>
        </goals>
        <configuration>
          <files>
            <file>version.properties</file>
          </files>
        </configuration>
      </execution>
    </executions>
  </plugin>

And then you will be able to put revision number and repo url to the manifest:

<manifest>
  <attribute name="Revision" value="${revision}" />
  <attribute name="Repository URL" value="${repourl}" />
</manifest>

Please also note that you will need to explicitly enable svn:keywords using subversion properties in order to get $Revision$ and $HeadURL$ substituted in your file with actual values. If you will decide to use version.properties, you will need to run following command:

svn propset svn:keywords Revision version.properties
svn propset svn:keywords HeadURL version.properties
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文