父pom中的内容,定义dev/pvt/api环境
<profiles> <profile> <id>dev</id> <properties> <profileActive>dev</profileActive> </properties> <activation> <activeByDefault>false</activeByDefault> </activation> </profile> <profile> <id>pvt</id> <properties> <profileActive>pvt</profileActive> </properties> <activation> <activeByDefault>true</activeByDefault> </activation> </profile> <profile> <id>api</id> <properties> <profileActive>api</profileActive> </properties> <activation> <activeByDefault>false</activeByDefault> </activation> </profile> </profiles>
springboot中的application.yml中的内容:
spring: application: name: model-service profiles: active: @profileActive@
子工程的pom文件中添加插件
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-resources-plugin</artifactId> <version>2.6</version> <executions> <execution> <id>copy-resources</id> <phase>validate</phase> <goals> <goal>copy-resources</goal> </goals> <configuration> <outputDirectory>${project.build.outputDirectory}</outputDirectory> <resources> <resource> <!-- 指定resources插件处理哪个目录下的资源文件 --> <directory>src/main/resources</directory> <filtering>true</filtering> </resource> </resources> </configuration> </execution> </executions> </plugin>
打包命令 -大P dev是环境,父pom中配置的
mvn install -P dev