我可以使用buildnumber-maven-plugin设置项目版本吗? [英] Can I set the project version with a buildnumber-maven-plugin?

查看:303
本文介绍了我可以使用buildnumber-maven-plugin设置项目版本吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将svn.revision添加到项目版本中作为内部版本号,但似乎无法这样做.我的jar具有正确的durin包装名称,但是它安装在我的本地存储库中,就像在设置版本时未定义$ {buildNumber}一样.

I'm trying to add the svn.revision to project version as a build number and can't seem to do so. My jar has the correct name durin packaging, but its installed in the my local repository it is as if ${buildNumber} is/was undefined when the version was set.

我得到foo-1.0.0-SNAPSHOT- $ {buildNumber} 而不是foo-1.0.0-SNAPSHOT- 304

I get foo-1.0.0-SNAPSHOT-${buildNumber} instead of foo-1.0.0-SNAPSHOT-304

有什么主意我做错了,还是在项目版本中添加修订版是个坏主意?感谢您的帮助.

Any idea what I'm doing wrong or is adding a revision to the project version a bad idea? Thanks for the help.

<project>
  ...
  <version>1.0.0-${release.identifier}-${buildNumber}</version>
  <properties>
    <release.identifier>SNAPSHOT</release.identifier>
  </properties>
  ...
  <build>
    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>buildnumber-maven-plugin</artifactId>
        <executions>
          <execution>
            <id>useLastCommittedRevision</id>
            <goals>
              <goal>create</goal>
            </goals>
            <configuration>
              <useLastCommittedRevision>true</useLastCommittedRevision>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  ...
</project>

推荐答案

问题有两个部分:

  1. 您要尝试在解析前将buildNumber设置为版本,因此它始终是${buildNumber}而不是解析后的值.

  1. You're trying to set the buildNumber into the version before it is resolved so it will always be ${buildNumber} rather than the resolved value.

您应该将buildNumber设置为构建中的finalName元素,而不是尝试动态更改版本.这将在本地存储库中创建具有预期名称的工件.

Instead of trying to dynamically change the version, you should set the buildNumber into the finalName element in the build. This will create the artifacts with the intended name in the local repository.

无论如何,安装插件将忽略finalName并将其部署为1.0.0-SNAPSHOT,我不知道解决该问题的方法.如果您按以下方式配置插件,则buildNumber将添加到清单中.

The install plugin will ignore the finalName and deploy it as 1.0.0-SNAPSHOT regardless, I don't know of a way to address that. The buildNumber is added to the Manifest if you configure the plugin as below.

因此您的配置将类似于:

So your configuration would be something like:

<version>1.0.0-${release.identifier}</version>
...
<build>
  <finalName>${project.artifactId}-${project.version}-${buildNumber}</finalName>
  ...
</build>


我会避免在SNAPSHOT项目上使用内部版本号.


I would avoid using build numbers on SNAPSHOT projects.

Maven提供了SNAPSHOT关键字来表示活动开发中的易失项目.因此,如果您引用的项目具有SNAPSHOT依赖版本,则Maven将自动检查更新,并使您的依赖保持同步.

Maven provides the SNAPSHOT keyword to signify a volatile project in active development. So if you reference a project with a SNAPSHOT dependency version, Maven will automatically check for updates and keep your dependencies in sync.

如果随后在该版本的末尾添加内部版本号,则必须手动更新依赖项,因此失去使用SNAPSHOT后缀的任何好处.

If you then add a build number to the end of that version, you will have to manually update the dependencies, so you lose any benefit of having the SNAPSHOT suffix.

我个人还是尽量避免使用内部版本号.如果必须更新项目,则只需更改版本号,或使用后缀beta-2RC2.如果您需要在SNAPSHOT中跟踪修订,我建议将其添加到清单中,以便您可以检查生成的来源,但可以使用标准的SNAPSHOT后缀来允许Maven正常解析版本.下面的配置显示了如何将修订版本添加到清单中.

I personally avoid using build numbers where possible anyway. If I have to update a project, I just bump the version number, or use a suffix like beta-2 or RC2. If you need to track the revision in the SNAPSHOT, I'd recommend adding it to the Manifest so you can check where the build originated, but use the standard SNAPSHOT suffix to allow Maven to resolve the versions normally. The configuration below shows how to add the revision to the Manifest.

就您的配置而言,假设您的SCM网址设置正确,对我来说似乎还可以.如果您的POM中没有SCM配置,则可能是问题所在.

As far as your configuration is concerned, it looks OK to me assuming your SCM url is set up correctly. If you have no SCM configuration in your POM that may be the problem.

您可以使用-X运行并检查插件是否显示任何未设置属性的输出吗?

Can you run with -X and check for any output from the plugin indicating why it isn't setting the property?

<plugin>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>buildnumber-maven-plugin</artifactId>
  <version>0.9.4</version>
  <executions>
    <execution>
      <id>useLastCommittedRevision</id>
      <phase>validate</phase>
      <goals>
        <goal>create</goal>
      </goals>
    </execution>
  </executions>
</plugin>
<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-jar-plugin</artifactId>
  <version>2.1</version>
  <configuration>
    <archive>
      <manifest>
        <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
      </manifest>
      <manifestEntries>
        <Implementation-Build>${buildNumber}</Implementation-Build>
      </manifestEntries>
    </archive>
  </configuration>
</plugin>

这篇关于我可以使用buildnumber-maven-plugin设置项目版本吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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