2010-08-31 98 views
3

我有更新從屬同級項目的依賴版本的問題。如何使用版本Maven插件更新從屬同級模塊的版本

我的簡化項目設置如下。

root 
|--parent 
|--tool-core 
|--tool 
|--functional-tests 

父項目包含所有全局屬性和依賴項管理。功能測試取決於工具,而工具取決於工具內核。根目錄pom.xml僅聚合(指定是否包含功能測試)並且父項目是所有項目的父項目。我不知道這是否微不足道,但父母並未包含在聚合中,因爲它已經是每個子項目的父項。

現在,我的問題是,如果我改變工具的版本versions:set。工具版本已更改,但對該工具的任何依賴關係均未更改。我應該怎麼做?我已經嘗試了或多或少隨機的其他目標,並嘗試閱讀手冊。

我已經嘗試過使用<dependencyManagement>部分並在父級版本中使用屬性,但這些屬性不會更新爲新版本。

任何幫助真的很感激。

加成

我得到一個消息 「忽略反應器的依賴:com.tool:工具:罐子:空:1.2.3」 的最好的。這是當我嘗試versions:use-latest-releases。但versions:display-dependency-updates確實顯示「本地依賴項」上有更新(功能測試取決於工具)。

更新

看來,Maven的做新版本從儲存庫,包括當地一個現在,我想它似乎很明顯查找。但是,這意味着必須在更新依賴關係之前將該工具構建並安裝到本地存儲庫。

我只是想知道這是否是作爲自己的項目進行集成測試的正確方法。我希望能夠立即更新版本。

更新

基本上我有以下設置。 toolfunctional-tests版本依賴項由parent項目定義。我省略了tool-core,因爲它可以作爲tool的一部分進行處理。

根:

<groupId>com.somecompany</groupId> 
<artifactId>x-reactor</artifactId> 
<packaging>pom</packaging> 
<version>1.0</version> 

<profiles> 
    <profile> 
     <id>cli</id> 
     <modules> 
      <module>tool</module> 
     </modules> 
    </profile> 
    <profile> 
     <id>deploy</id> 
     <modules> 
      <module>tool</module> 
      <module>functional-tests</module> 
     </modules> 
    </profile> 
</profiles> 

父:

<groupId>com.somecompany</groupId> 
<artifactId>x-parent</artifactId> 
<packaging>pom</packaging> 
<version>1.0</version> 

<dependencyManagement> 
    <dependencies> 
     <dependency> 
      <groupId>com.somecompany</groupId> 
      <artifactId>tool</artifactId> 
      <version>3.2.3</version> 
     </dependency> 
    </dependencies> 
</dependencyManagement> 

工具:

<parent> 
    <groupId>com.somecompany</groupId> 
    <artifactId>x-parent</artifactId> 
    <version>1.0</version> 
    <relativePath>../parent/pom.xml</relativePath> 
</parent> 

<groupId>com.somecompany</groupId> 
<artifactId>tool</artifactId> 
<packaging>jar</packaging> 
<version>3.2.3</version> 

官能測試:

<parent> 
    <groupId>com.somecompany</groupId> 
    <artifactId>x-parent</artifactId> 
    <version>1.0</version> 
    <relativePath>../parent/pom.xml</relativePath> 
</parent> 

<groupId>functional-tests</groupId> 
<artifactId>functional-tests</artifactId> 
<version>0.1</version> 
<packaging>pom</packaging> 

<dependencies> 
    <dependency> 
     <groupId>com.somecompany</groupId> 
     <artifactId>tool</artifactId> 
    </dependency> 
</dependencies> 
+0

你可以給你不同模塊的poms片段......(只有模塊的父母部分和模塊部分)。 – khmarbaise 2010-08-31 07:42:06

回答

2

顯然,必須以與需要更新的pom.xml所在的路徑相同的路徑運行目標versions:use-latest-versions。我通過將版本移動到父項目並僅更新它來解決此問題。我對這個解決方案不太滿意,因爲版本插件似乎不支持降級版本。此外,新版本從(本地)存儲庫獲得,這意味着該工具必須在更新版本之前構建。我認爲這是我最初的問題。

下面就來解決這個問題的腳本:(?剛纔)

#!/bin/bash 

if [[ $# -lt 1 ]]; then 
    echo "Usage: $0 [version number]" 
    exit 1 
fi 

function revert_version() { 
    mvn -Pall versions:revert > /dev/null 
    echo "ERROR: Failed updating the version" 
    cat mvn_out.txt 
    exit 1 
} 

v=$1 
profile=cli 
echo "Updating the version to $v..." 
mvn -P$profile versions:set -DnewVersion=$v -DartifactId=tool -q 
[ $? -eq 0 ] || revert_version 

echo "Building the tool..." 
mvn -P$profile install > /dev/null 
[ $? -eq 0 ] || revert_version 

echo "Updating the dependencies..." 
mvn versions:use-latest-versions -Dincludes=com.somecompany:* -f parent/pom.xml -q 
[ $? -eq 0 ] || revert_version 
mvn -Pall versions:commit -q 
[ $? -eq 0 ] || revert_version 
6

我遇到了同樣的問題,目前正在與「使用,發佈」的目標,很高興的是,版本插件支持這種情況下,由參數「excludeReactor = false」! :-)

相關問題