Maven: property to activate profile in sub-modules

一笑奈何 提交于 2019-12-17 19:59:21

问题


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>

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>

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

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

The maven version is latest: 3.2.1.

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


回答1:


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:

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.

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.



来源:https://stackoverflow.com/questions/23492528/maven-property-to-activate-profile-in-sub-modules

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!