0

我尝试使用 buildnumber-maven-plugin 将我当前的 SVN 修订号添加到战争的清单文件中。

在 pom.xml 我添加了:

         <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>buildnumber-maven-plugin</artifactId>
            <version>1.1</version>
            <executions>
                <execution>
                    <phase>validate</phase>
                    <goals>
                        <goal>create</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <doCheck>false</doCheck>
                <doUpdate>false</doUpdate>
                <revisionOnScmFailure>0.0.1</revisionOnScmFailure>
            </configuration>
        </plugin>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.0.2</version>
            <configuration>
                <archive>
                    <manifest>
                        <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
                    </manifest>
                    <manifestEntries>
                        <Implementation-Build>x ${buildNumber}</Implementation-Build>
                    </manifestEntries>
                </archive>
            </configuration>
        </plugin>

但部署文件后,清单文件如下所示:

Manifest-Version: 1.0
Built-By: my.name
Build-Jdk: 1.6.0_33
Implementation-Title: Java EE 6 webapp project
Implementation-Version: 0.0.1-SNAPSHOT
Implementation-Vendor-Id: com.company.my
Implementation-Build: x ${buildNumber}
Created-By: Maven Integration for Eclipse

因此${buildNumber}无论出于何种原因都不会评估。(而且revisionOnScmFaulure选项似乎不起作用。(出于调试原因,我添加了“x”。)

当我将项目作为 maven build 运行时,出现以下错误:

"Unknown lifecycle phase "create". You must specify a valid lifecycle phase or a goal in the format <plugin-prefix>:<goal> or <plugin-group-id>:<plugin-artifact-id>[:<plugin-version>]:<goal>. Available lifecycle phases are: validate, initialize, generate-sources, process-sources, generate-resources, process-resources, compile, process-classes, generate-test-sources, process-test-sources, generate-test-resources, process-test-resources, test-compile, process-test-classes, test, prepare-package, package, pre-integration-test, integration-test, post-integration-test, verify, install, deploy, pre-clean, clean, post-clean, pre-site, site, post-site, site-deploy."

但是,将目标更改为 create 以外的任何内容都不能解决问题并导致验证器错误。

4

1 回答 1

3

这就是它适用于rexsl 项目的方式(参见他们的pom.xml):

<build>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>buildnumber-maven-plugin</artifactId>
            <version>1.1</version>
            <configuration>
                <buildNumberPropertyName>buildNumber</buildNumberPropertyName>
                <doCheck>false</doCheck>
                <doUpdate>false</doUpdate>
                <getRevisionOnlyOnce>true</getRevisionOnlyOnce>
            </configuration>
            <executions>
                <execution>
                    <phase>generate-resources</phase>
                    <goals>
                        <goal>create</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
    <pluginManagement>
        <plugins>
            <plugin>
                <artifactId>maven-jar-plugin</artifactId>
                <version>2.1</version>
                <configuration>
                    <archive>
                        <manifestEntries>
                            <ReXSL-Version>${project.version}</ReXSL-Version>
                            <ReXSL-Build>${buildNumber}</ReXSL-Build>
                        </manifestEntries>
                    </archive>
                </configuration>
            </plugin>
        </plugins>
    </pluginManagement>
</build>
于 2012-11-19T19:45:45.413 回答