今天在構建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]