How to package only the configuration files of the current environment when springboot is packaged in multiple environments

there are application.properties and application-dev.properties and application-prod.properties files in the 1.springboot project.

where environment switching can be performed in application.properties

spring.profiles.active=dev

now I package with the following parameters, but these three configuration files are always included in the packaged file.

mvn clean package -Dmaven.test.skip=true -Dprofiles.active=dev
mvn clean package -Dmaven.test.skip=true -Pprod

what I actually want is that the development environment packages only one configuration file . Could you tell me how to operate it?

Mar.31,2021

create three folders under the resource folder, and place their respective application.properties files respectively

src/main/resources/dev/application.properties
src/main/resources/test/application.properties
src/main/resources/pro/application.properties

define three profile first in pom.xml

    <profiles>
        <profile>
            <!--  -->
            <id>dev</id>
            <properties>
                <profiles.active>dev</profiles.active>
                <modifier></modifier>
            </properties>
            <activation>
                <activeByDefault>true</activeByDefault>       <!-- profile -->         
            </activation>
        </profile>
        <profile>
            <!--  -->
            <id>test</id>
            <properties>
                <profiles.active>test</profiles.active>
                <modifier>-test</modifier>        
            </properties>
        </profile>
        <profile>
            <!--  -->
            <id>pro</id>
            <properties>
                <profiles.active>pro</profiles.active>                
                <modifier>-pro</modifier>                
            </properties>
        </profile>
    </profiles>

under the build tag, exclude all, and then add the profile: currently activated by the-P parameter

    <build>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <!--  -->
                <excludes>
                    <exclude>test/*</exclude>
                    <exclude>pro/*</exclude>
                    <exclude>dev/*</exclude>
                </excludes>
            </resource>
            <resource>
                <directory>src/main/resources/${profiles.active}</directory>
            </resource>
        </resources>

finally, add the-P parameter at compile time, for example:

mvn -Ppro package
Menu