激活配置文件时在 Maven 子模块中添加依赖项

2023-12-20

我和家长有一个项目pom.xml定义配置文件,以及debug轮廓 :

<profile>
    <id>debug-true</id>
    <activation>
        <property>
            <name>debug</name>
            <value>true</value>
        </property>
    </activation>
</profile>

我希望我的子模块之一添加依赖项jboss-seam-debug当个人资料debug被激活。

我写了这个孩子的 pom.xml :

<profiles>
    <profile>
        <id>debug-true</id>
        <dependencies>
            <dependency>
                <groupId>org.jboss.seam</groupId>
                <artifactId>jboss-seam-debug</artifactId>
            </dependency>
        </dependencies>
    </profile>
</profiles>

但它不起作用,当我指定时,该依赖项不是依赖项树的一部分-Ddebug=true...就像孩子们的 pom.xml 重新定义了我的debug轮廓 ...

你知道我该如何添加吗jboss-seam-debug依赖于我的子模块时property debug有价值true ?


实际上,这是我的全部需求,但稍微复杂一些。

这是我的父母pom.xml :

<profiles>
    <profile>
        <id>env-dev</id>
        <activation>
            <activeByDefault>true</activeByDefault>
            <property>
                <name>env</name>
                <value>dev</value>
            </property>
        </activation>
        <properties>
            <debug>true</debug>
    ... other properties ...
        </properties>
    </profile>
    ...

一般来说,我只是通过-Denv=dev on the mvn命令行并希望我的子模块激活jboss-seam-debug仅当财产debug被定义为true所以我把它写在子模块中pom.xml :

<profiles>
    <profile>
        <id>debug-true</id>
        <activation>
            <property>
                <name>debug</name>
                <value>true</value>
            </property>
        </activation>
        <dependencies>
            <dependency>
                <groupId>org.jboss.seam</groupId>
                <artifactId>jboss-seam-debug</artifactId>
            </dependency>
        </dependencies>
    </profile>
    ...

仅通过传递是行不通的-Denv=dev因为我没有通过system财产-Ddebug=true,这是maven由我的父母激活的财产pom.xml,而我的孩子们没有“看到”......


这是因为配置文件在 Maven 中没有继承。这意味着debug-true子 POM 中的配置文件不会继承父 POM 中配置文件的激活(也称为debug-true.

您有两种可能性来解决这个问题:

1) call mvn -Pdebug-true这将触发每个 POM 中相应的配置文件

2)添加激活码each POM

我个人更喜欢第一种解决方案。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

激活配置文件时在 Maven 子模块中添加依赖项 的相关文章

随机推荐