Under springboot multi-module and multi-environment deployment, the packaging of the selection environment brought by the relativePath tag fails, and the default environment is always packaged

1. **The cause of the problem:
when using the idea tool to create a springboot multi-module project, new-project

 

 

 

Then the created project has such a configuration in pom
<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.7.5< /version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    If it is a sub-module, this paragraph should be modified to inherit the POM of its parent project.
    If it is a parent project, I keep this configuration
    and configure multiple profiles in the parent project
    <profiles>
        <profile>
            <!-- Local development environment -->
            <id>dev</id>
            <properties>
                <!-- The tag name here will be spliced ​​with resource -->
                <activatedProperties>dev</activatedProperties>


            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
        </profile>
        <profile>
            <!-- 测试环境 -->
            <id>test</id>
            <properties>
                <activatedProperties>test</activatedProperties>
            </properties>
        </profile>
        <profile>
            <!-- 生产环境 -->
            <id>prod</id>
            <properties>
                <activatedProperties>prod</activatedProperties>
            </properties>
        </profile>
    </profiles>

2. Later, due to the addition of a new environment, a new profile was added to the parent POM as follows :
<profiles>
        <profile>
            <!-- Local development environment -->
            <id>dev</id>
            <properties>
                <!- - The tag name here will be spliced ​​with resource -->
                <activatedProperties>dev</activatedProperties>
            </properties>
            <!-- This is configured as the default option -->
            <activation>
                <activeByDefault>true</activeByDefault> </activeByDefault>
            </ activation>
        </profile>
        <profile>
            <!-- test environment-->
            <id>test</id>
            <properties>
                <activatedProperties>test</activatedProperties>
            </properties>
        </profile>
        <profile>
            <!-- Test environment--> /**Newly added environment configuration file name
            <id>test-hz</id>
            <properties>
                <activatedProperties>test-hz< /activatedProperties>
            </properties>
        </profile>

        <profile>
            <!-- production environment-->
            <id>prod</id>
            <properties>
                <activatedProperties>prod</activatedProperties>
            </properties>
        </profile>
    </profiles>
    Then deploy the project in the test environment, select the newly added configuration file test-hz,
    use the packaging statement mvn clean package -P test-hz
    and then package the report
    The requested profile "test-hz" could not be activated because it does not exist. The
    newly added profile cannot be found, but the environment has been added to my POM, and the configuration file also exists.
    3. The reason for the above problems is because of the relativePath label in the parent POM.
    If this tag is not written, the parent POM in the project path is used as the jar dependency basis by default. But if I wrote an empty tag, I just wrote an empty tag <relativePath/> <!-- lookup parent from repository -->, then maven always gets the POM from the remote warehouse when packaging, and In the remote warehouse, I have not added the profile of test-hz, so I have not been able to find the environment configuration of test-hz. Instead, dev is used as the default environment for configuration.
   4. The solution is to delete the relativePath tag in the parent POM.

Guess you like

Origin blog.csdn.net/weixin_48363639/article/details/127451134