7

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 Answer 1

17

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.