2016-08-01 211 views
0

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

<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的生命周期中安装插件应该采取新的版本。

+0

版本,Maven的插件:设定目标,仅用于内部的命令行运行和NOT lifecycle ...永远不会工作,导致版本 - maven-plugin:set目标将改变pom.xml文件,但在运行期间,pom.xml已经被加载到内存中,因此结果是你将总是安装旧的版本。您使用哪个Maven版本? – khmarbaise

+0

嗨,谢谢你的回答,我使用Maven 3.3.x.从命令行使用版本插件后,它的工作!也许有人有相同的用例:build-helper:parse-version版本:set -DnewVersion = $ {parsedVersion.majorVersion}。$ {parsedVersion.minorVersion}。$ {parsedVersion.incrementalVersion} - $ {SVN_REVISION} – desert

回答

0

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> 

所以,你可以通过这个叫行家:

mvn -Drevision=1.2.3 -Dsha1=SVNRevision-SNAPSHOT clean package 
+0

谢谢,但是对于我的用例来说,构建助手插件就足够了,它会读取当前版本并附加svn修订版本号,我不想在命令行上提供该版本。 – desert

相关问题