tags:

views:

557

answers:

4

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"&gt;
    <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"&gt;
    <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.

A: 

Hi Mike,

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"&gt;
    <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
Ah, sorry...that was just an obfuscation typo =) The parent project is named 'build' IRL.
mikek
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
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
A: 

Are you running mvn in the child directory?

Jim Downing
nope, running mvn install on the parent, naturally. As I said to Chris above, running the parent once sans child dumps a copy of the pom to my local repo and lets it build.
mikek
+3  A: 

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
A: 

how can we get the module's version into parent pom?

Raamjaney
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