0

我使用versions-maven-plugin 来更新项目版本。我想使用此更新版本安装工件,但 maven-install 插件使用旧版本。我必须如何配置项目以实现所描述的行为?

<plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>build-helper-maven-plugin</artifactId>
            <executions>
                <execution>
                    <phase>validate</phase>
                    <goals>
                        <goal>parse-version</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <propertyPrefix>parsedVersion</propertyPrefix>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>versions-maven-plugin</artifactId>
            <executions>
                <execution>
                    <id>update-version</id>
                    <phase>validate</phase>
                    <goals>
                        <goal>set</goal>
                        <goal>commit</goal>
                    </goals>
                    <configuration>
                        <newVersion>${parsedVersion.majorVersion}.${parsedVersion.minorVersion}.${parsedVersion.incrementalVersion}-${SVN_REVISION}</newVersion>
                    </configuration>
                </execution>
            </executions>
        </plugin>

通常我希望关于 maven 生命周期,安装插件应该采用新版本,因为版本插件是在验证阶段执行的。

4

1 回答 1

0

Maven 3.2.1 开始,可以使用属性作为版本,这意味着您可以在 pom 文件中提供如下内容:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

  <modelVersion>4.0.0</modelVersion>

  <parent>
    <groupId>com.soebes.smpp</groupId>
    <artifactId>smpp</artifactId>
    <version>2.2.1</version>
  </parent>

  <groupId>com.soebes.examples.j2ee</groupId>
  <artifactId>parent</artifactId>
  <version>${revision}</version>
  <packaging>pom</packaging>

此外,您当然也可以在这样的多模块构建的父元素中使用它:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

  <modelVersion>4.0.0</modelVersion>

  <parent>
    <groupId>com.soebes.examples.j2ee</groupId>
    <artifactId>parent</artifactId>
    <version>${revision}</version>
  </parent>

  <artifactId>service</artifactId>
  <packaging>ejb</packaging>

这意味着您可以通过以下方式运行 Maven:

mvn -Drevision=1.2.3-SNAPSHOT install

或者简单地发布:

mvn -Drevision=1.2.3 install

这里的缺点是您需要始终在命令行或 CI 作业中进行修订。除此之外,还可以使用其他东西,例如${changelist}${sha1}当然可以组合使用。所以你可以采用这样的建议:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

  <modelVersion>4.0.0</modelVersion>

  <parent>
    <groupId>com.soebes.smpp</groupId>
    <artifactId>smpp</artifactId>
    <version>2.2.1</version>
  </parent>

  <groupId>com.soebes.examples.j2ee</groupId>
  <artifactId>parent</artifactId>
  <version>${revision}-${sha1}</version>
  <packaging>pom</packaging>

所以你可以通过这个调用maven:

mvn -Drevision=1.2.3 -Dsha1=SVNRevision-SNAPSHOT clean package
于 2016-08-02T07:20:54.690 回答