激活配置文件时,在Maven子模块中添加依赖关系 [英] Adding dependencies in a Maven sub-module when a profile is activated
问题描述
pom.xml
定义配置文件,一个调试
个人资料: <个人资料>
< id> debug-true< / id>
< activate>
< property>
< name> debug< / name>
< value> true< / value>
< / property>
< / activation>
< / profile>
我希望我的一个子模块添加依赖关系 jboss-seam -appbug
当配置文件 debug
被激活。
我写了这个孩子pom。 xml:
<个人资料>
<个人资料>
< id> debug-true< / id>
<依赖关系>
<依赖关系>
< groupId> org.jboss.seam< / groupId>
< artifactId> jboss-seam-debug< / artifactId>
< / dependency>
< / dependencies>
< / profile>
< / profiles>
但是它不起作用,当依赖关系不指定 -Ddebug = true
...这就像孩子pom.xml重新定义我的调试
个人资料...
您是否知道如何在属性<...>中添加 jboss-seam-debug
依赖关系到子模块/ strong> debug
的值为 true
?
其实,这是我的全部需要,这是一个更复杂的。
这是我的父母 pom.xml
:
<个人资料>
<个人资料>
< id> env-dev< / id>
< activate>
< activeByDefault> true< / activeByDefault>
< property>
< name> env< / name>
< value> dev< / value>
< / property>
< / activation>
<属性>
< debug> true< / debug>
...其他属性...
< / properties>
< / profile>
...
一般来说,我只是通过 -Denv = dev
在 mvn
命令行上,希望我的子模块激活 jboss-seam-debug
只有当属性 debug
被定义为 true
,所以我在子模块中写了 pom.xml
:
<个人资料>
<个人资料>
< id> debug-true< / id>
< activate>
< property>
< name> debug< / name>
< value> true< / value>
< / property>
< / activation>
<依赖关系>
<依赖关系>
< groupId> org.jboss.seam< / groupId>
< artifactId> jboss-seam-debug< / artifactId>
< / dependency>
< / dependencies>
< / profile>
...
仅通过传递 -Denv = dev
,因为我不通过系统属性 -Ddebug = true
,这是 maven 属性,由我的父项 pom.xml
激活,我的孩子不会看到...
这是因为个人资料不会在maven中继承。这意味着孩子POM中的 debug-true
不会继承在父POM中也称为 debug-true
的配置文件的激活。
您有两种解决办法:
1)调用 mvn -Pdebug -true
将触发每个POM中的相应配置文件
2)在每个 POM
个人我会推荐第一个解决方案。
I have a project with a parent pom.xml
which define profiles, and a debug
profile :
<profile>
<id>debug-true</id>
<activation>
<property>
<name>debug</name>
<value>true</value>
</property>
</activation>
</profile>
I want that one of my sub-modules adds the dependency jboss-seam-debug
when the profile debug
is activated.
I written this children pom.xml :
<profiles>
<profile>
<id>debug-true</id>
<dependencies>
<dependency>
<groupId>org.jboss.seam</groupId>
<artifactId>jboss-seam-debug</artifactId>
</dependency>
</dependencies>
</profile>
</profiles>
But it doesn't work, that dependency is not part of the dependency tree when I specify -Ddebug=true
... it's like the children pom.xml re-defines my debug
profile ...
Do you know how could I add jboss-seam-debug
dependency to my sub-module when the property debug
has the value true
?
Actually, here is my full need which is a bit more complex.
Here is my parent 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>
...
Generally, I just pass -Denv=dev
on the mvn
command line and wanted my sub-module to activate jboss-seam-debug
only when property debug
is defined to true
so I wrote that in the sub-module 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>
...
which didn't work only by passing -Denv=dev
because I don't pass the system property -Ddebug=true
, it's the maven property which is activated by my parent pom.xml
, and that my children doesn't "see" ...
it's because profiles are not inhertited in maven. This means debug-true
in child POM does not inhertif the activation of profile in parent POM also called debug-true
.
You have two possibilities to solve this:
1) call mvn -Pdebug-true
which will trigger the coresponding profile in each POM
2) add activation code in each POM
Personally I would prefere first solution.
这篇关于激活配置文件时,在Maven子模块中添加依赖关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!