1、配置文件pom.xml
<!--配置参数-->
<profiles>
<!-- mvn clean package -Pprod -->
<profile>
<id>prod</id>
<properties>
<package.environment>prod</package.environment>
</properties>
<activation>
<!-- 默认的,不加参数时执行这个profile
<activeByDefault>true</activeByDefault> -->
</activation>
</profile>
<!-- clean install -Ptest -->
<profile>
<id>test</id>
<properties>
<package.environment>test</package.environment>
</properties>
</profile>
</profiles>
<build>
<finalName>base-system</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
</plugin>
<!-- resource插件 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<!-- <version>3.1.0</version> -->
<executions>
<execution>
<id>copy-resources</id>
<phase>compile</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<!-- 覆盖原有文件 -->
<overwrite>true</overwrite>
<outputDirectory>${project.build.outputDirectory}</outputDirectory>
<!-- 待处理的资源定义 -->
<resources>
<resource>
<!-- 指定resources插件处理哪个目录下的资源文件 -->
<directory>src/main/resources/${package.environment}</directory>
<filtering>false</filtering>
</resource>
</resources>
</configuration>
<inherited></inherited>
</execution>
</executions>
</plugin>
</plugins>
</build>
2、maven项目的resources目录下新增prod和test的文件夹(prod对应正式服、test对应测试服)
将配置文件application.yml、logback.xml复制一份到prod和test,并将配置文件的配置信息修改为相应的环境信息。
3、maven打包命令:
正式服:mvn clean package -Pprod
测试服:mvn clean package -Ptest