Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Child not finding parent pom in flat structured multi module maven build

Tags:

maven-2

I'm setting up a multi module project with a flat structure, i.e. parent and child are in the same base directory. Parent is defined as

<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>company</groupId>
    <artifactId>parent</artifactId>
    <packaging>pom</packaging>
    <version>1-0-SNAPSHOT</version>
    <name>child</name>
    <modules>
        <module>../child</module>
    </modules>
(...)

while the child it defined as

<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">
    <parent>
        <groupId>company</groupId>
        <artifactId>parent</artifactId>
        <version>1.0-SNAPSHOT</version>
</parent>
    <modelVersion>4.0.0</modelVersion>
    <groupId>company</groupId>
<artifactId>child/artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>child</name>
(...)

(Company and project names obfuscated)

What's occurring is that the module (child) is complaining that it can't find the parent, i.e:

Reason: Cannot find parent: company:child for project: company:child:war:1.0-SNAPSHOT for project company:child:war:1.0-SNAPSHOT

Is there an obvious solution to this that I've missed, or is it ill advised to use a flat project structure?

Edit: Fixed a typo.

like image 242
mikek Avatar asked Nov 05 '09 15:11

mikek


2 Answers

Use the <relativePath> element as described in Example 5 of the Introduction to the POM:

<project>
  <parent>
    <groupId>company</groupId>
    <artifactId>parent</artifactId>
    <version>1.0-SNAPSHOT</version>
    <relativePath>.../parent/pom.xml</relativePath>
  </parent>
  <modelVersion>4.0.0</modelVersion>
  <groupId>company</groupId>
  <artifactId>child</artifactId>
  <packaging>war</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>child</name>
  ...
</project>
like image 113
Pascal Thivent Avatar answered Nov 11 '22 22:11

Pascal Thivent


The parent POM version is 1-0-SNAPSHOT, rather than 1.0-SNAPSHOT.

like image 2
Mike Gage Avatar answered Nov 11 '22 21:11

Mike Gage