今天在构建dp-onedata的时候出现一个问题,问题描述以下html
根目录的pom文件以下react
<groupId>com.xxx.xxx</groupId> <artifactId>dponedata</artifactId> <packaging>pom</packaging> <version>1.0-SNAPSHOT</version> <modules> <module>dponedata-common</module> <module>dponedata-web</module> </modules>
dponedata有2个子模块,分别是common模块和web模块,其中web模块依赖commot模块 web
<parent> <artifactId>dponedata</artifactId> <groupId>com.xxx.xxx</groupId> <version>1.0-SNAPSHOT</version> </parent> <modelVersion>4.0.0</modelVersion> <artifactId>dponedata-web</artifactId> <version>1.0-SNAPSHOT</version> <packaging>war</packaging> <dependencies> <dependency> <groupId>com.xxx.xxx</groupId> <artifactId>dponedata-common</artifactId> <version>${dponedata-common.version}</version> </dependency> </dependencies>
common模块配置即parent的子模块apache
<parent> <artifactId>dponedata</artifactId> <groupId>com.xxx.xxx</groupId> <version>1.0-SNAPSHOT</version> </parent> <modelVersion>4.0.0</modelVersion> <artifactId>dponedata-common</artifactId> <version>1.0-SNAPSHOT</version> <packaging>jar</packaging>
其中common模块和web模块分别使用了autocofig作变量值的替换app
<build> <finalName>dponedata-web</finalName> <plugins> <!-- 添加此插件以使用autoconf --> <plugin> <groupId>com.alibaba.citrus.tool</groupId> <artifactId>autoconfig-maven-plugin</artifactId> <version>1.2</version> <executions> <execution> <phase>package</phase> <goals> <goal>autoconfig</goal> </goals> </execution> </executions> </plugin> </plugins> </build> <build> <finalName>dponedata-common</finalName> <plugins> <!-- 添加此插件以使用autoconf --> <plugin> <groupId>com.alibaba.citrus.tool</groupId> <artifactId>autoconfig-maven-plugin</artifactId> <version>1.2</version> <executions> <execution> <phase>package</phase> <goals> <goal>autoconfig</goal> </goals> </execution> </executions> </plugin> </plugins> </build>
autofonfig的使用能够参考http://docs.alibaba-inc.com:8090/display/RC/autoconfig 或者官网 http://openwebx.org/docs/autoconfig.htmlmaven
这里打包很正常,打完common的jar包再打web的war包,autocofing也起了做用作变量值的替换ide
下面使用了assemble插件机型打包,把web包打成dponedata的tgz包ui
<id>tgz</id> <!-- 应用名.war(压缩包解压后的目录名) --> <baseDirectory>dponedata.war</baseDirectory> <formats> <format>tar.gz</format> </formats> <fileSets> <fileSet> <!-- 要压缩的目录,请按实际目录填写 --> <directory>dponedata-web/target/dponedata-web</directory> <!-- 输出的目录,此处为空便可 --> <outputDirectory></outputDirectory> <includes> <include>**/**</include> </includes> </fileSet> </fileSets>
可是问题出现了,这个tgz包中的变量值是没有替换的,看下mvn的log以下:插件
[INFO] Reactor Summary: [INFO] [INFO] dponedata .......................................... SUCCESS [ 6.601 s] [INFO] dponedata-common ................................... SUCCESS [ 4.451 s] [INFO] dponedata-web ...................................... SUCCESS [ 3.641 s]
看起来是是先打了跟项目的包,再去打了common和web包,因此web包中的变量已经替换,可是根路径的tgz包没有生成code
因此咱们要尽可能控制打包顺序。让打包的顺序变成 commont-》web-》all
pom的打包顺序是基于 topologic sorting的 能够参考这个文档:https://en.wikipedia.org/wiki/Topological_sorting
官网的reactor sorting以下 http://maven.apache.org/guides/mini/guide-multiple-modules.html
大体就如下几个规则
a project dependency on another module in the build
a plugin declaration where the plugin is another modules in the build
a plugin dependency on another module in the build
a build extension declaration on another module in the build
the order declared in the <modules> element (if no other rule applies)
根据第一个原则,父项目由于引入了全部须要的依赖要第一个执行,因此将其余2个子module的父项目都设置成公共的pom
<parent> <groupId>com.xxx</groupId> <artifactId>parent</artifactId> <version>1.0.2</version> </parent>
这时候打包的顺序就对了
[INFO] Reactor Summary: [INFO] [INFO] dponedata-common ................................... SUCCESS [ 2.938 s] [INFO] dponedata-web ...................................... SUCCESS [ 6.180 s] [INFO] dponedata .......................................... SUCCESS [ 6.570 s]