Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 246
monksy Avatar asked Oct 09 '13 20:10

monksy


People also ask

What is the packaging type of an aggregator pom in a multi module Maven project?

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.

What is parent POM in Maven POM xml?

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.

What is packaging type of parent project in a multi module Maven project?

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 .

How to declare a parent POM file?

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

What is parent pom in Maven?

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.

What is the difference between parent pom and parent Module 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.

What is the relationship between parent and child modules in Maven?

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).


Video Answer


1 Answers

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

like image 99
Frederic Close Avatar answered Sep 23 '22 12:09

Frederic Close