2016-08-01 212 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

相關問題