49

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.

naXa stands with Ukraine
  • 35,493
  • 19
  • 190
  • 259
monksy
  • 14,156
  • 17
  • 75
  • 124

1 Answers1

43

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

Frederic Close
  • 9,389
  • 6
  • 56
  • 67
  • 2
    When i'm using this type of variable, I got some warnings at the begining of maven's build saying that properties can be unknown or kind of. Is there a way to avoid or do I just have to ignore these warnings? thanks – Kyu_ Jun 02 '14 at 09:08
  • 2
    for what kind of properties d o you have that warning ? is it this problem : http://stackoverflow.com/questions/1981151/warning-on-using-project-parent-version-as-the-version-of-a-module-in-maven-3 ? – Frederic Close Jun 02 '14 at 18:54
  • 9
    This only works if the child pom has the other one as a parent. Properties are inherited, but not passed to submodules. – bmurauer Aug 26 '19 at 08:46
  • 1
    Properties are reevaluated for each submodule. This means, for example, if you set a property to a path that is relative to the parent, it will be reevaluated at the submodules path. For example, say you set the following property in the parent pom: ${basedir}/. If you reference the something.path property in the child, it will be reevaluated with the following value: parent/submodule/. – senfo Apr 21 '21 at 11:17
  • Out of the box, Maven does not allow you to use custom properties defined in a parent module inside child modules. Period. To enable it, you must be using a "CI-friendly version" of Maven (3.5.0-beta-1 or newer) *and* you must also include the Flatten Maven Plugin inside your parent's pom. Though there are nuances with various Maven versions, combined with various IDE's and versions, none of the aforementioned comments are correct without meeting the two criteria I mentioned. – Matt Jan 11 '22 at 19:45