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一系列,不知道是什么原因,或者是我的写法有错误,如果有哪位大神知道,还望不吝赐教。

 

posted @ 2017-11-23 17:13  周博文  阅读(2524)  评论(0编辑  收藏  举报