Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven profile properties are not "overriding"

I have Maven multi-module project with such structure:

parent-pom-project

-- module1

-- module2

At the parent-pom-project I have such pom.xml

    <modules>
        <module>module1</module>
    </modules>
...
    <profiles>
        <profile>
           <id>local</id>
           <properties>
               <prop>local_prop</prop>
           </properties>
        </profile>
        <profile>
           <id>test</id>
           <modules>
                <module>module2</module>
           </modules>
           <properties>
               <prop>test_prop</prop>
           </properties>
        </profile>
    </profiles>

At all pom.xml files I have such tag:

<build>
    <resources>
        <resource>
            <directory>src/main/resources</directory>
            <filtering>true</filtering>
        </resource>
        <resource>
            <directory>src/test/resources</directory>
            <filtering>true</filtering>
        </resource>
    </resources>
</build>

At module1 and module2 in resource directory I have properties files with such text:

prop=${prop}

The problem is that after

mvn clean install

or

mvn clean install -Ptest

or even

mvn clean install -P test

I get

prop=local_prop

If I user test profile for build module2 is also builded, but properties are used from local profile. I use Maven 3.0.3. Anybody have any ideas?

like image 727
Nazar Avatar asked Feb 16 '12 11:02

Nazar


People also ask

How do you override parent POM properties in a child pom?

in the pom. xml properties , try to get auto-completion/suggestion to override a parent property using CTRL+O (like override method in Java), CTRL+SPACE(+SPACE) (open auto-completion/suggestion) or ALT+INSERT (insert Managed Dependency, Dependency Template...)

How do maven profiles work?

A profile in Maven is an alternative set of configuration values which set or override default values. Using a profile, you can customize a build for different environments. Profiles are configured in the pom. xml and are given an identifier.


1 Answers

You could try to use the mvn help:effective-pom -Ptest command to see the paramters used in your build.

See http://maven.apache.org/plugins/maven-help-plugin/plugin-info.html for more details.

like image 196
Olivier.Roger Avatar answered Sep 21 '22 13:09

Olivier.Roger