1、多個(gè)依賴項(xiàng)目(以common,sso為例)存放于同級(jí)目錄下(這個(gè)目錄暫稱(chēng)為頂級(jí)目錄)
2、在頂級(jí)目錄中創(chuàng)建sso-pom.xml,sso-pom-dev.xml,sso-pom-test.xml
2.1、編寫(xiě)sso-pom.xml,sso-pom-dev.xml,sso-pom-test.xml如下:
1 公共配置:
2 <artifactId>sso</artifactId>
3 <groupId>com.xxx.sso</groupId>
4 <version>3.2.0-SNAPSHOT</version>
5 <packaging>pom</packaging>
6
7 不同配置:
8 sso-pom.xml:
9 <modules>
10 <module>cdcommon/trunk/pom.xml</module>
11 <module>sso/trunk/pom.xml</module>
12 </modules>
13
14 sso-pom-dev.xml:
15 <modules>
16 <module>cdcommon/trunk/pom-dev.xml</module>
17 <module>sso/trunk/pom-dev.xml</module>
18 </modules>
19
20 sso-pom-test.xml:
21 <modules>
22 <module>cdcommon/trunk/pom-test.xml</module>
23 <module>sso/trunk/pom-test.xml</module>
24 </modules>
3、每個(gè)項(xiàng)目(common,sso)目錄中創(chuàng)建一個(gè)pom.xml,pom-dev.xml,pom-test.xml
3.1、編寫(xiě)pom.xml,pom-dev.xml,pom-test.xml,替換不同環(huán)境下的配置文件
1 <properties>
2 <buildDirectory>e:/mvn_out/cdcommon</buildDirectory>
3 <sourceDirectory>src/main/java</sourceDirectory>
4 <fileName>common-1.0</fileName>
5 <commonProperties>src/main/resources/config/common-dev.properties</commonProperties>
6 </properties>
7
8 <plugins>
9 <plugin>
10 <groupId>org.apache.maven.plugins</groupId>
11 <artifactId>maven-antrun-plugin</artifactId>
12 <version>1.6</version>
13 <executions>
14 <execution>
15 <id>compile</id>
16 <phase>compile</phase>
17 <configuration>
18 <target>
19 <echo message="********************** copy profile common.properties file *************************"/>
20 <copy file="${commonProperties}"
21 tofile="${buildDirectory}/classes/common.properties" overwrite="true"/>
22 </target>
23 </configuration>
24 <goals>
25 <goal>run</goal>
26 </goals>
27 </execution>
28 </executions>
29 </plugin>
30 <plugins>
4、運(yùn)行命令,打包不同環(huán)境下的發(fā)布版本
生產(chǎn):mvn package -f sso-pom.xml
開(kāi)發(fā):mvn package -f sso-pom-dev.xml
測(cè)試:mvn package -f sso-pom-test.xml