另外參考:https://blog.csdn.net/linhao19891124/article/details/73872303
maven中指定build一個project中幾個特定的子modules
問題由來:
一個項目可能會有多個子module,在特定情況下可能只需要build其中幾個module。
例如我的項目的目錄結構如下
myproject
|------------module_one
|------------module_two
|------------module_three
|------------module_four
|------------module_five
|------------module_six
|------------module_seven
|------------pom.xml
解決方法一:
例:我想要build module_three,module_five,module_seven三個子module
在根pom同一級目錄運行如下命令:
mvn clean install -pl module_three,module_five,module_seven
也可以在此命令上加上以下參數
-am 不僅build module_three,module_five,module_seven這三個,而且build這些子module require的其他項目,require是指其parent項目。
-amd 不僅build module_three,module_five,module_seven這三個,而且build依賴這三個module的項目,如module_other。
解決方法二:
增加一個profile,如:
<profiles> <profile> <id>patch_001</id> <properties> </properties> <modules> <module>module_three</module> <module>module_five</module> <module>module_seven</module> </modules> </profile> </profiles>
然后運行maven命令:
mvn clean install -Ppatch_001 #這樣也可以只build這三個子module
PS:我采用第二種方法的時候,發現在profile這樣定義了所要build的module后,外面就不能再定義需要build的module了,否則就會按照外面定義的來build一系列,不知道是什么原因,或者是我的寫法有錯誤,如果有哪位大神知道,還望不吝賜教。