【问题标题】:How to pass arguments via command line to maven settings.xml?如何通过命令行将参数传递给 maven settings.xml?
【发布时间】:2020-07-02 12:49:02
【问题描述】:

我需要根据 Spring Boot Maven 应用程序中的环境细节激活配置文件。我在 settings.xml

中配置了配置文件
    <profiles>
        <profile>
            <id>dev</id>
        <activation>
                <activeByDefault>false</activeByDefault> </activation>
            <repositories>
                <repository>
                    <id>devRepo</id>
                    <url>https://customRepo/maven/v1</url>
                    <releases>
                        <enabled>true</enabled>
                        <updatePolicy>always</updatePolicy>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                        <updatePolicy>always</updatePolicy>
                    </snapshots>
                </repository>
            </repositories>

        </profile>
        <profile>
            <id>qa</id>
        <activation>
                <activeByDefault>false</activeByDefault> </activation>
            <repositories>
                <repository>
                    <id>qaRepo</id>
                    <url>https://customRepo2/maven/v1</url>
                    <releases>
                        <enabled>true</enabled>
                        <updatePolicy>always</updatePolicy>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                        <updatePolicy>always</updatePolicy>
                    </snapshots>
                </repository>
            </repositories>
        </profile>

    </profiles>

我尝试使用命令-Pdev 激活配置文件

mvn spring-boot:run -s settings.xml -D"spring-boot.run.profiles"=dev help:active-profiles

但配置文件未正确激活。 但是通过添加 activeprofiles 标签可以正常工作。

    <activeProfiles>
        <activeProfile>dev</activeProfile>
    </activeProfiles>

但我需要激活特定的配置文件环境,例如

    <activeProfiles>
        <activeProfile>$env</activeProfile>
    </activeProfiles>

我们可以通过任何方式将参数传递给 settings.xml 文件中的activeProfile 吗?类似这样-Denv

参考:

Maven: How do I activate a profile from command line?

Configure active profile in SpringBoot via Maven

https://mkyong.com/maven/maven-profiles-example/

http://maven.apache.org/settings.html

【问题讨论】:

    标签: java maven-3 settings


    【解决方案1】:

    注意这行描述: “当所有指定的条件都满足时,激活就会发生,尽管不是一次都需要。”来自个人资料部分的http://maven.apache.org/settings.html 并考虑在您的项目中定义 application.properties 并使用此配置添加行: spring.profiles.active=@spring.profiles.active@ 我希望这项工作。

    【讨论】:

    • 谢谢,我已经尝试添加属性,但仍然没有成功。
    猜你喜欢
    • 1970-01-01
    • 2021-09-29
    • 2021-11-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-25
    • 2012-06-19
    • 2017-04-20
    相关资源
    最近更新 更多