8

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.

mikek
  • 1,555
  • 17
  • 30
  • 4
    for some reason I read the title of this as "Child not finding parent porn"... lol – Jakub Nov 05 '09 at 16:19
  • 1
    Parent uses version `1-0`, whereas the the child refers to `1.0`.. (notice the difference between the dash and the dot) Or is this another typo? – Tim Nov 06 '09 at 10:34
  • how can we get the module's version into parent pom? –  Jan 26 '11 at 15:50
  • You don't. POMs are independent of each other, so to find each other they need to know each other's version beforehand. Also, I suggest you formulate this as a proper question and not a response to mine. – mikek Jan 26 '11 at 15:50

3 Answers3

14

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>
Pascal Thivent
  • 562,542
  • 136
  • 1,062
  • 1,124
2

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

Mike Gage
  • 21
  • 1
  • Hi, this question been answered for a long time now (And the accepted answer was the same as your). You should put effort in non-answered one and try bringing something new to the conversation. Good luck! – Simon Boudrias Nov 13 '12 at 02:56
0

The child pom does not reference the parent pom, it references another artifact named 'build'. It should read:

<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>
(...)
Chris Gummer
  • 4,772
  • 1
  • 24
  • 17
  • Ah, sorry...that was just an obfuscation typo =) The parent project is named 'build' IRL. – mikek Nov 05 '09 at 16:18
  • No problems, what about the parent's version? It's set at 1.0-SNAPSHOT, whilst the child references a version of the parent at 1.7.0-SNAPSHOT. – Chris Gummer Nov 05 '09 at 16:23
  • Agh...same story. I've been staring at this code for way too long. If I build the parent sans child everything works from then on in (because the parent is in my local repo), so it's not a typo issue. – mikek Nov 05 '09 at 16:29