单模块的Maven配置文件 [英] Maven profile for single module
问题描述
mvn package
,或者我可以使用reactor来构建一个模块。 我可以使用个人资料做同样的事情吗?通过修改POM?谢谢
编辑
如果不可能从POM,我可以从settings.xml?
要实现这个配置文件,你可以使用两个配置文件,一个 ; activeByDefault>
与所有模块,另一个只有想要的模块。这样的:
<个人资料>
<个人资料>
< id> all< / id>
< activate>
< activeByDefault> true< / activeByDefault>
< / activation>
< modules>
< module> module-1< / module>
...
< module> module-n< / module>
< / modules>
< / profile>
<个人资料>
< id> module-2< / id>
< modules>
< module> module-2< / module>
< / modules>
< / profile>
<个人资料>
然后调用如下:
mvn -Pmodule-2包
:
- 您需要从POM中移动
< modules>
默认配置文件(因为< modules>
从配置文件只是加法的,它们不会隐藏在POM中声明的模块)。 - 通过将其标记为
< activeByDefault>
,如果没有其他活动,则会选择默认配置文件,否则其他情况会被停用。
甚至可以参数化模块的名称,并将其作为属性传递:
<型材>
...
< profile>
< id> module-x< / id>
< activate>
< property>
< name> module-name< / name>
< / property>
< / activation>
< modules>
< module> $ {module-name}< / module>
< / modules>
< / profile>
<个人资料>
并调用maven这样:
mvn -Dmodule-name = module-2 package
但是是一个糟糕的实现IMHO,我更喜欢 -pl
高级反应堆选项(更少xml,更多的功能和灵活性):
mvn -pl module-2 package
I have a multi module maven project, which builds successfully, I'd like to build just one of the modules I have. How would I do that with profiles ? I could do it from console in two ways, one way is go to the child module and mvn package
or I could use reactor to build just one module.
Can I do the same thing with profiles? By modifying POM? Thank you
EDIT
If is impossible from POM, can I do it from settings.xml ?
To implement this with profiles, you could use two profiles, one <activeByDefault>
with all modules and another one with the wanted module only. Something like this:
<profiles>
<profile>
<id>all</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<modules>
<module>module-1</module>
...
<module>module-n</module>
</modules>
</profile>
<profile>
<id>module-2</id>
<modules>
<module>module-2</module>
</modules>
</profile>
<profiles>
And then call it like this:
mvn -Pmodule-2 package
Two things to note here:
- You need to move the
<modules>
from the POM in a "default" profile (because<modules>
from a profile are only additive, they do not hide the modules declared in the POM). - By marking it as
<activeByDefault>
, the "default" profile will be picked if nothing else is active but deactivated if something else is.
One could even parametrize the name of the module and pass it as property:
<profiles>
...
<profile>
<id>module-x</id>
<activation>
<property>
<name>module-name</name>
</property>
</activation>
<modules>
<module>${module-name}</module>
</modules>
</profile>
<profiles>
And invoke maven like this:
mvn -Dmodule-name=module-2 package
But this is a poor implementation IMHO, I prefer the -pl
"advanced" reactor options (less xml, much more power and flexibility):
mvn -pl module-2 package
这篇关于单模块的Maven配置文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!