1:“maven父節點”或“當前pom文件加上”以下profiles。(project節點下)
<profiles> <profile> <id>dev</id><!--開發環境(默認)--> <activation> <!--默認環境--> <activeByDefault>true</activeByDefault> </activation> <properties> <testVerSion>xxxxxDev</testVerSion><!--動態參數標簽--> <vvv>xxxxxxxxx</vvv> </properties> </profile> <profile>
<id>test</id><!--測試環境--> <properties> <testVerSion>xxxxxTest</testVerSion><!--動態參數標簽--> <vvv>vvv</vvv> </properties> </profile> </profiles>
2:pom文件引入jar包(必須要有“默認環境”)
<dependency>
<groupId>com.zxy.product</groupId>
<artifactId>system-api</artifactId>
<version>${testVerSion}</version> <!--動態參數讀取-->
</dependency>
3:打包傳遞環境值(測試環境 )
mvn clean package -P test 這里test傳入后,會自動匹配到 <id>test</id> 的配置