我使用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生命周期的角度来看,安装插件应该采用新版本,因为版本插件是在验证阶段执行的。
发布于 2016-08-02 15:20:55
从Maven 3.2.1 there is a possibility to use properties as versions开始,这意味着你可以在你的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 packagehttps://stackoverflow.com/questions/38701810
复制相似问题