2012-07-05 145 views
0

Maven是否可以在一系列依賴項版本中多次構建和測試項目?在一系列依賴關係中構建多個Maven構件

例如,說我有以下庫:

groupId  artifactId version 
com.example library  1.0 
com.example library  1.1 
com.example library  2.0 
com.example library  2.2 

而且我的構建產生罐子神器:output.jar

我可以產生針對每個庫的版本如下:

groupId  artifactId version result 
com.example library  1.0  output_1.0.jar 
com.example library  1.1  output_1.1.jar 
com.example library  2.0  output_2.0.jar 
com.example library  2.2  output_2.2.jar 

回答

2

嘗試型材http://maven.apache.org/guides/introduction/introduction-to-profiles.html

<profiles> 
    <profile> 
    <id>version1.0</id> 
    <dependencies> 
     <dependency> 
     <groupId>com.example</groupId> 
     <artifactId>library</artifactId> 
     <version>1.0</version> 
     </dependency> 
    </dependencies> 
    <build> 
     <finalName>${project.artifactId}-library-1.0.jar</finalName> 
    </build> 
    </profile> 
    <profile> 
    <id>version1.1</id> 
    <dependencies> 
     <dependency> 
     <groupId>com.example</groupId> 
     <artifactId>library</artifactId> 
     <version>1.1</version> 
     </dependency> 
    </dependencies> 
    <build> 
     <finalName>${project.artifactId}-library-1.1.jar</finalName> 
    </build> 
    </profile> 
</profiles> 

然後當你調用行家,: MVN -Pversion1.1

你的一個配置文件可能應該被激活了,這樣就可以無需激活特定的配置文件進行編譯。

<activation> 
    <activeByDefault>true</activeByDefault> 
</activation> 
+0

ps:這不會多次構建它,因爲您必須爲每個不同的配置文件調用maven來測試編譯。要麼創建一個shell /批處理腳本來執行該操作,要麼使用構建軟件(jenkins,等等......)就可以完成該操作。 – Matt 2012-07-06 00:29:13

+0

正是我在找的,謝謝。太糟糕了,我不能指定一系列的依賴關係,這將是非常光滑的。 – 2012-07-06 18:51:48

1

您可以使用jenkins或hudson的矩陣項目功能。請參閱https://wiki.jenkins-ci.org/display/JENKINS/Building+a+matrix+project

多配置項目對於您的構建將執行許多類似構建步驟的實例非常有用,否則您將會複製步驟。

但是你不能以這種方式在本地機器上構建項目。

+0

這可能與Matt的答案中的Maven配置文件很好地配合。我會給它一個鏡頭。 – 2012-07-06 18:53:07