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.
2. Maven's Multi-Module Project. A multi-module project is built from an aggregator POM that manages a group of submodules. In most cases, the aggregator is located in the project's root directory and must have packaging of type pom.
A parent pom. xml file (or super POM) in Maven is used to structure the project in order to avoid redundancies and duplicate configurations by using an inheritance between different pom. xml files. If any dependency or properties are configured in both - parent and child - pom.
For a multimodule Maven project, In the root directory, there is a pom. xml there which is the parent pom and its packaging is pom .
A parent POM can be declared with packaging pom. It is not meant to be distributed because it is only referenced from other projects. Maven parent pom can contain almost everything and those can be inherited into child pom files e.g
Parent POM Maven supports inheritance in a way that each pom.xml file has the implicit parent POM, it's called Super POM and can be located in the Maven binaries. These two files are merged by Maven and form the Effective POM.
The main difference between multi-module parent pom and normal pom is its packaging type. For a multi-module parent pom, its packaging type becomes ‘pom’. Also in parent pom, it is referring to the submodules with <submodule> tag.
Modules inside a project can have two types of relationships: parent/child and dependency/dependent. When selecting a parent (aggregator), Maven automatically selects the child modules as well. Similarly, Maven excludes child modules of an excluded parent (aggregator).
You should try to use ${databasedriver}
directly in your child pom.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With