[英]How to activate a profile in a maven submodule using a property?
I am using Maven 3.6.0 and OpenJDK8 on Ubuntu 18.04 (also tested with Alpine Linux). 我在Ubuntu 18.04上使用了Maven 3.6.0和OpenJDK8(也已在Alpine Linux上进行了测试)。
I have a pom.xml
in the root of my project that includes my submodules : 我在项目的根目录中有一个
pom.xml
,其中包含我的子模块:
...
<modules>
<module>mysubmodule</module>
</modules>
...
In the mysubmodule
folder, the pom.xml
has a profile that I want to activate based on a property passed to the mvn
executable: 在
mysubmodule
文件夹中, pom.xml
具有要基于传递给mvn
可执行文件的属性来激活的配置文件:
...
<profile>
<id>my-profile</id>
<activation>
<property>
<name>activateMyProfile</name>
</property>
</activation>
...
</profile>
...
I then execute mvn to start the build, but the profile is never activated: 然后,我执行mvn来开始构建,但是该配置文件从未被激活:
mvn -DactivateMyProfile release:prepare
from the root of my project, the profile is never activated and never runs mvn -DactivateMyProfile release:prepare
,则永远不会激活配置文件,也不会运行 mvn release:prepare
from the root of my project, the profile is never run. mvn release:prepare
,则永远不会运行配置文件。 I also tried the inverse: 我也尝试过相反的方法:
...
<profile>
<id>my-profile</id>
<activation>
<property>
<name>!doNotActivateMyProfile</name>
</property>
</activation>
...
</profile>
...
mvn -DdoNotActivateMyProfile release:prepare
from the root of my project, the profile is still executed mvn -DdoNotActivateMyProfile release:prepare
,则仍然执行配置文件 mvn release:prepare
from the root of my project, the profile is also executed mvn release:prepare
,也会执行配置文件 It looks like mvn
is not able to see the properties being passed through the command line. 看起来
mvn
无法看到通过命令行传递的属性。 What is the correct way to activate a profile in a submodule using a property? 使用属性激活子模块中的配置文件的正确方法是什么?
As I am using the maven release plugin, parameters must be passed using the -Darguments
argument. 当我使用Maven版本插件时,必须使用
-Darguments
参数传递参数。
For example, instead of using mvn -DactivateMyProfile release:prepare
, the correct invocation is: mvn -Darguments=-DactivateMyProfile release:prepare
例如,代替使用
mvn -DactivateMyProfile release:prepare
,正确的调用是: mvn -Darguments=-DactivateMyProfile release:prepare
If there are multiple arguments, use mvn -Darguments="-DactivateMyProfile -DsomeOtherArg -DanotherArg=something" release:prepare
如果有多个参数,请使用
mvn -Darguments="-DactivateMyProfile -DsomeOtherArg -DanotherArg=something" release:prepare
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.