在Maven中,配置文件可以覆盖模块(不包括任何模块)吗? [英] In Maven, can a profile override the modules (to not include any)
问题描述
在maven
中,一旦在pom.xml
中定义了modules
,所有配置文件便会汇总其中定义的模块:(仅相关部分)
In maven
, once you define your modules
in you pom.xml
all profiles aggregate the modules defined in them: (relevant part only)
<project>
<modules>
<module>module1</module>
</modules>
<profiles>
<profile>
<id>pr1</id>
<modules>
<moudule>module2</module>
</modules>
如果执行mvn clean
,它将把命令传递给module1
.
If you perform a mvn clean
it will pass the command to module1
.
如果您发布mvn clean -Ppr1
,它将传递给module1
和module2
.
If you issue mvn clean -Ppr1
it will pass along to module1
and module2
.
我想知道在maven 3
中是否可以有一个带有子模块的pom.xml
并覆盖它.我的意思是执行一个配置文件,而不是将自己的模块添加到构建中,例如:
I wonder if in maven 3
it is possible to have a pom.xml
with submodules and override this. I mean to execute a profile that instead of add their own modules to the build force those like:
<project>
<!-- omitted -->
<modules>
<!-- modules -->
</modules>
<build>
<!-- build -->
</build>
<profiles>
<profile>
<!-- This profile with no modules -->
</profile>
</profiles>
</project>
这个要求听起来可能很愚蠢,但是我只想知道插件配置中是否存在类似的机制.
The requirement might sound silly, but I just want to know if there is a mechanism like in plugin configuration.
<configuration self.combine="override"
致谢!
ssedano
推荐答案
这是不可能的.配置文件配置始终与主配置合并,因此您只能在您的情况下添加模块.
It's not possible. Profile configuration is always merged with main configuration, so you only can add modules in your case.
但是,您可以做的是创建某种默认"配置文件(通过<activation>
部分中的<activeByDefault>true</activeByDefault>
),该配置文件在没有其他配置文件被调用时启用,并将默认模块的列表放在此处.然后,当在Maven构建调用中未指定任何配置文件时,将使用此默认"配置文件,但是当您显式调用至少一个配置文件时,则没有使用此配置文件,因此您可以通过这种方式从头开始定义模块的列表.
What you can do instead, however, is to create a some kind of "default" profile (by <activeByDefault>true</activeByDefault>
in <activation>
section) that is enabled when no other profiles are invoked and put your default modules' list there. Then, when no profile is specified on Maven build call, this "default" profile is used, but when you call explicitly at least one profile, it's not, so you can this way define modules' list from scratch.
这篇关于在Maven中,配置文件可以覆盖模块(不包括任何模块)吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!