在使用Maven-BuildNumber-Plugin 1.0 beta 4时,除非我使用 <format> 在配置中标记。一旦我使用 <format><item>buildnumber</item> 标签,我得到了一个自动收入号码,但它不再对应于SVN修订版,我不知道如何将其恢复。有没有一种方法可以使用SVN修订号 <format>?该文档并不清楚。

有帮助吗?

解决方案

BuildNumber-Maven-Plugin非常古怪,这可能仍然是Beta的原因。该格式仅适用于您希望将Java消息格式应用于和在大多数情况下,仅适用于时间戳和文字字符串。如果您不需要时间戳,则在获取“颠覆修订号”号时不要使用格式选项。如果您使用该格式,则像您指示的那样,它将为您提供一个始终以一个而不是SCM版本编号增量的构建号。

如果您确实需要时间戳或从buildnumber插件中派生的其他项目以及颠覆修订版,请将每个项目作为单独的执行执行。这是如何使用插件的两个单独执行来获取subverison修订号和构建时间戳的示例:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>buildnumber-maven-plugin</artifactId>
    <version>1.0-beta-4</version>
    <executions>
        <execution>
            <id>generate-buildnumber</id>
                <phase>validate</phase>
            <goals>
                <goal>create</goal>
            </goals>
            <configuration>
                <useLastCommittedRevision>true</useLastCommittedRevision>
                <buildNumberPropertyName>buildRevision</buildNumberPropertyName>
            </configuration>
        </execution>
        <execution>
            <id>generate-timestamp</id>
            <phase>validate</phase>
            <goals>
                <goal>create</goal>
            </goals>
            <configuration>
                <format>{0,date,yyyy-MM-dd HH:mm:ss}</format>
                <items>
                    <item>timestamp</item>
                </items>
                <buildNumberPropertyName>buildDateTime</buildNumberPropertyName>
            </configuration>
        </execution>
    </executions>
</plugin>

制作此工作的关键是使用buildnumberpropertyname元素。检查插件的 用法 有关Java消息格式有用性的更多信息,页面是。

其他提示

从外观上看。如果您使用格式配置,则必须使用其中一个默认项目。

这里:

指定java.text.messageformat指定的消息。 此触发要读的“项目”配置

然后是 这里:

根据Java.text.messageformat指定的格式消息的相应项目。特殊项目值是“时间戳”和“ buildNumber/d*”。

另外,如果您查看Mojo的代码 这里 几件事支持这一点:

if ( format != null )
{
    if ( items == null )
    {
        throw new MojoExecutionException(
             " if you set a format, you must provide at least one item, "
             + "please check documentation " );
    }

和:

else
{
    // Check if the plugin has already run.
    revision = project.getProperties().getProperty(
        this.buildNumberPropertyName );
    if ( this.getRevisionOnlyOnce && revision != null)
    {
        getLog().debug( "Revision available from previous execution" );
        return;
    }

通过它的声音,您要求提供一个新功能(顺便说一句,这不是一个坏主意)。我会这样提交 这里.

我确实遇到了同样的问题,片刻中,我认为 @jean-rémyrevy作品建议的解决方案..但是没有出于某种原因。

事实证明,在BuildNumber-Maven-Plugin-1.2中,他们增加了对称为Scmversion的特殊属性的支持。截至目前,v1.2在Maven存储库中尚未可用,尽管该插件的网站表明它是GA。因此,您需要检查源(http://svn.codehaus.org/mojo/tags/buildnumber-maven-plugin-1.2/)并构建它($ MVN安装)。这还将在您的本地存储库中安装插件。

此后,这样做:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>buildnumber-maven-plugin</artifactId>
    <version>1.2</version>
    <executions>
        <execution>
                <phase>validate</phase>
            <goals>
                <goal>create</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <format>{0,date,yyyy-MM-dd HH:mm:ss}.{1}</format>
            <items>
                <item>timestamp</item>
                <item>scmVersion</item>
            </items>
        </configuration>

</plugin>

有一个令人信服的原因是插件开发人员已经完成了这一点。获得项目构建时间戳的推荐方法如下:

<project>
  <properties>
    <maven.build.timestamp.format>yyyy-MM-dd HH:mm:ss</maven.build.timestamp.format>
    <buildDateTime>${maven.build.timestamp}</buildDateTime>    
  </properties>
</project>

因此,您需要的只是获得一个修订号,可以根据其文档对BuildNumber-Maven-Plugin进行单一调用,可以做得很好。

ps每次调用插件时,有一个执行而不是两个(如所提供的)保存;)

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top