0

I cant access, from a Maven module, to a property defined in the properties section of the parent. As a matter of fact When I launch the build below the warName is the default one.

This is the parent Pom

....
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.speed.pms</groupId>
    <artifactId>PMS-Main</artifactId>
    <version>1.0.0</version>
    <packaging>pom</packaging>
        <name>PMS Main Build Project</name>

    <properties>
            <context-root>PMS-CUSTOM</context-root>
        </properties>
     <modules>
        <module>../PMS-WEB</module>
     </modules>
....

And this is the module

...
 <parent>
        <groupId>com.speed.pms</groupId>
        <artifactId>PMS-Main</artifactId>
        <version>1.0.0</version>
      </parent>
    <artifactId>PMS-WEB</artifactId>
    <packaging>war</packaging>
    <name>PMS-WEB Webapp</name>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <web.resource.dir>src/main/webapp</web.resource.dir>
    </properties>
    <build>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.4</version>
                <configuration>
                    <!-- Context root from parent project -->
                    <warName>${context-root}</warName>
                    <webResources>
                        <resource>
                            <directory>${web.resource.dir}</directory>
                        </resource>
                    </webResources>
                </configuration>
            </plugin>
....

While I can use the ${project.parent.arctifactId} property. I try also ${project.parent.properties.context-root} but without success. It should be simple but I cant understand Which is my errror? Shouldn't be the properties inherited from the parent in a Module?

Panciz
  • 2,183
  • 2
  • 30
  • 54

2 Answers2

2

People in the Maven user list help me to find the solution. I post the reply

while your ../PMS-WEB section in parent pom references the child in the same directory, your / is undefined, therefore expecting the parent to be one level up, not on the same level.

I change the child module parent section in

<parent>
    <groupId>com.speed.pms</groupId>
    <artifactId>PMS-Main</artifactId>
    <version>1.0.0</version>
    <relativePath>../PMS-Main/</relativePath>
</parent>

and everithings works.

Thanks to milos

Davide

Panciz
  • 2,183
  • 2
  • 30
  • 54
0

There are another solution. Maven 3 in first step looking for parent pom.xml in one level up directory. If they can not find this file there then try to extract pom.xml from repository.

So solution is to install parent project before run maven in child.

Koziołek
  • 2,791
  • 1
  • 28
  • 48