Maven多环境构建
Maven支持让我们配置多套环境,每套环境中可以指定自己的maven属性,
profiles元素支持定义多套环境的配置信息,配置如下用法:
<profiles>
<!-- 开发环境使用的配置 -->
<profile>
<id>dev</id>
<activation>
<!--默认激活当前配置-->
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<jdbc.url>jdbc:mysql://192.168.10.128:3306/dev?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useSSL=false</jdbc.url>
<jdbc.driver>com.mysql.jdbc.Driver</jdbc.driver>
<jdbc.username>root</jdbc.username>
<jdbc.password>123456</jdbc.password>
<jdbc2.url>jdbc:mysql://192.168.10.128:3306/dev2?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useSSL=false</jdbc2.url>
<jdbc2.driver>com.mysql.jdbc.Driver</jdbc2.driver>
<jdbc2.username>root</jdbc2.username>
<jdbc2.password>123456</jdbc2.password>
</properties>
</profile>
<!-- 测试环境使用的配置 -->
<profile>
<id>test</id>
<properties>
<jdbc.url>jdbc:mysql://192.168.10.128:3306/test?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useSSL=false</jdbc.url>
<jdbc.driver>com.mysql.jdbc.Driver</jdbc.driver>
<jdbc.username>root</jdbc.username>
<jdbc.password>123456</jdbc.password>
</properties>
</profile>
<!-- 线上环境使用的配置 -->
<profile>
<id>prod</id>
<properties>
<jdbc.url>jdbc:mysql://192.168.10.128:3306/prod?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useSSL=false</jdbc.url>
<jdbc.driver>com.mysql.jdbc.Driver</jdbc.driver>
<jdbc.username>root</jdbc.username>
<jdbc.password>123456</jdbc.password>
</properties>
</profile>
</profiles>
另外一种多环境选择方式:
<profiles>
<!-- 开发环境使用的配置 -->
<profile>
<id>dev</id>
<activation>
<!--默认激活当前配置-->
<activeByDefault>false</activeByDefault>
</activation>
<build>
<filters>
<filter>src/main/resources/jdbc-dev.properties</filter>
</filters>
</build>
</profile>
<!-- 测试环境使用的配置 -->
<profile>
<id>test</id>
<activation>
<!--默认激活当前配置-->
<activeByDefault>true</activeByDefault>
</activation>
<build>
<filters>
<filter>src/main/resources/jdbc-test.properties</filter>
</filters>
</build>
</profile>
<!-- 线上环境使用的配置 -->
<profile>
<id>prod</id>
<build>
<filters>
<filter>src/main/resources/jdbc-prod.properties</filter>
</filters>
</build>
</profile>
</profiles>