Maven将SVN版本添加到清单

时间:2012-11-19 11:27:21

标签: svn maven

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

在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之外的任何内容都无法解决问题并导致验证程序错误。

1 个答案:

答案 0 :(得分:2)

这就是它的工作原理,例如rexsl project(参见他们的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>