Getting the properties defined in the parent POM inside the child modules [multi-module projects]

monksy picture monksy · Oct 9, 2013 · Viewed 44.4k times · Source

I'm having issues with passing properties from a super pom [of the multimodule project] into a child pom.

At the moment I have the following files: superpom

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0                               http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>...</groupId>
    <artifactId>meta-all</artifactId>
    <version>1.0</version>
    <packaging>pom</packaging>
    <properties>
        <databasedriver>net.sourceforge.jtds.jdbc.Driver</databasedriver>
    </properties>
    <modules>
        <module>child1</module> 
    </modules>
</project>

The child pom

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>...</groupId>
    <artifactId>child1</artifactId>
    <version>1.0-SNAPSHOT</version>
    <build>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>sql-maven-plugin</artifactId>
                <version>1.5</version>
                <!-- JDBC Driver -->
                <dependencies>
                    <dependency>
                        <groupId>net.sourceforge.jtds</groupId>
                        <artifactId>jtds</artifactId>
                        <version>1.3.1</version>
                    </dependency>
                </dependencies>
                <configuration>
                    <driver>${project.parent.databasedriver}</driver>
                  ...
                    <autocommit>true</autocommit>
                    <delimiter>GO</delimiter>
                    <delimiterType>row</delimiterType>
                </configuration>
                <executions>

Howeve, I'm not sure why I can't get the plugin configuration to retrieve the super pom's properties.

Answer

Frederic Close picture Frederic Close · Oct 9, 2013

You should try to use ${databasedriver} directly in your child pom.