Spring Boot项目maven分环境打包

Spring Boot项目maven分环境打包


[toc]


一、环境配置

image-20220720100426358

二、pom添加“repackage”打包插件和“profiles”配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
//添加插件
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
//添加profiles
<profiles>
<profile>
<id>local</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<spring.profiles.active>local</spring.profiles.active>
<profileActive>local</profileActive>
</properties>
</profile>
<profile>
<id>dev</id>
<properties>
<spring.profiles.active>dev</spring.profiles.active>
<profileActive>dev</profileActive>
</properties>
</profile>
<profile>
<id>pro</id>
<properties>
<spring.profiles.active>pro</spring.profiles.active>
<profileActive>pro</profileActive>
</properties>
</profile>
</profiles>

三、application.yml配置

1
2
3
spring:
profiles:
active: @profileActive@

四、打包

1
2
3
4
5
6
//默认local
mvn clean package
//dev环境
mvn clean package -P dev
//pro环境
mvn clean package -P pro

Spring Boot项目maven分环境打包
http://example.com/49494.html
作者
John Doe
发布于
2022年9月5日
许可协议