Maven:激活子模块中的配置文件的属性 [英] Maven: property to activate profile in sub-modules

查看:329
本文介绍了Maven:激活子模块中的配置文件的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个多模块maven项目,并且它具有可运行的不同平台,例如JBoss 4和JBoss7.我们指定platform属性,然后将其用作工件的分类器以及对子模块中特定于平台的配置文件,例如:

We have a multi-module maven project, and it has different platforms to run on, like JBoss 4 and JBoss 7. We specify the platform property, and then use it as a classifier for artifacts, and for activation of the platform-specific profile in sub-modules, like:

<activation>
    <property>
        <name>platform</name>
        <value>jboss71x</value>
    </property>
</activation>

在这些配置文件中的

中,我们除其他外,指定了提供的依赖项的版本. 例如.我们确实导入了jboss父pom:

in these profiles, we, among other things, specify the versions of provided dependencies. E.g. we do import of jboss parent pom:

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.jboss.as</groupId>
            <artifactId>jboss-as-parent</artifactId>
            <version>${dependencies.jbossas7.version}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>

因此,当我们将属性指定为命令行参数(-Dplatform=jboss71x)时,它就可以正常工作.

So when we specify the property as a command-line argument (-Dplatform=jboss71x), it works OK.

但是,如果在根pom.xml的<properties>部分中设置了该属性(我也尝试在父pom中进行设置),则好像错过了父pom的版本:

But when the property is set in <properties> section in root pom.xml (I also tried to set it in parent pom), looks like the versions from parent pom are missed:

[ERROR]     'dependencies.dependency.version' for commons-lang:commons-lang:jar is missing. @ line 46, column 21
[ERROR]     'dependencies.dependency.version' for commons-beanutils:commons-beanutils:jar is missing. @ line 56, column 21
[ERROR]     'dependencies.dependency.version' for commons-collections:commons-collections:jar is missing. @ line 61, column 21

maven版本是最新的:3.2.1

The maven version is latest: 3.2.1.

为什么会发生这种情况,我们如何在pom.xml中而不是在命令行中指定此属性值?

Why this happens, and how can we specify this property value in pom.xml, not in command line?

推荐答案

可惜,您不可能做自己想做的事情.我花了数小时尝试相同的事情,然后在Codehaus网站上找到此说明 :

Alas, it is not possible to do what you are trying to do. I spent hours attempting the same thing before finding this note on the Codehaus website:

请注意,只有在Maven命令行上设置的属性才能激活配置文件.在POM,父POM或其他配置文件中设置的属性无效.

Note only properties set on the Maven command line can activate profiles. Properties set in the POM, the parent POM, or other profiles have no effect.

基本上,配置文件激活发生在POM处理的早期,即在插入所有属性之前.从本质上讲,这意味着激活配置文件的属性必须在构建的开始就具有定义的值-作为系统属性,因此在命令行上也是如此-因为配置文件激活发生在Maven处理任何<properties>元素之前.对于类似的StackOverflow问题,有一个答案,其中提供了更多详细信息和背景文档.

Basically, profile activation happens very early in the POM processing, before all of the properties are interpolated. Essentially this means the property activating a profile must have a defined value at the very beginning of a build - as a system property, so on the command line - because profile activation occurs before Maven processes any <properties> elements. There is an answer to a similar StackOverflow question that gives more detail and background docs.

这篇关于Maven:激活子模块中的配置文件的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆