views:

35

answers:

1

I have a parent project with 5 children having also dependencies between each other. I used both inheritence with <parent> element in the children pom.xml and aggregation with <module> element in the parent.

My parent pom looks like this:

<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>com.domain</groupId>
<artifactId>Parent</artifactId>
<packaging>pom</packaging>
<version>RELEASE</version>
<name>Parent</name>

<modules>
    <module>../Child1</module>
    <module>../Child2</module>
    <module>../Child3</module>
    <module>../Child4</module>
    <module>../Child5</module>
</modules>

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>com.domain</groupId>
            <artifactId>Child1</artifactId>
            <version>RELEASE</version>
        </dependency>
        <dependency>
            <groupId>com.domain</groupId>
            <artifactId>Child2</artifactId>
            <version>RELEASE</version>
        </dependency>
    </dependencies>
</dependencyManagement>
</project>

Child3 pom looks like this:

<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>com.domain</groupId>
<artifactId>Child3</artifactId>
<name>Child3</name>
<packaging>war</packaging>

<parent>
    <artifactId>Parent</artifactId>
    <groupId>com.domain</groupId>
    <version>RELEASE</version>
</parent>

<dependencies>
    <dependency>
        <groupId>com.domain</groupId>
        <artifactId>Child1</artifactId>
    </dependency>
    <dependency>
        <groupId>com.domain</groupId>
        <artifactId>Child2</artifactId>
    </dependency>
</dependencies>
</project>

Everything works fine when I run mvn install on Parent or Child1. But when I run it on Child3 I get the following errors:

[INFO] Failed to resolve artifact.
Missing:
----------
1) com.domain:Child1:jar:RELEASE
...
2) com.domain:Child2:jar:RELEASE

What's wrong with my set-up?

+2  A: 

I won't really try to solve the issue of your current approach but will rather cover what I consider as the best practice in this case. Feel free to adopt it or not :)

First of all, please note that the RELEASE (and LATEST) is a special keyword (not sure you are aware of this) and RELEASE is somehow misused here (a parent with a version defined to RELEASE doesn't really make sense). Anyway, these special keywords were a bad idea and are deprecated (I'm not sure they're supported in Maven3) for the sake of build reproducibility, just avoid using them.

So, use a SNAPSHOT version if the project is under active development instead i.e. modify the parent like this:

<project>

  <modelVersion>4.0.0</modelVersion>

  <groupId>com.domain</groupId>
  <artifactId>Parent</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>pom</packaging>

  <name>Parent</name>

  <modules>
    <module>../Child1</module>
    <module>../Child2</module>
    <module>../Child3</module>
    <module>../Child4</module>
    <module>../Child5</module>
  </modules>

</project>

Note that I removed the dependencyManagement element, I don't think it provides much added value for internal dependencies of a multi module build and recommend using the the ${project.groupId} and ${project.version} built-in properties instead when declaring them:

<project>
  <modelVersion>4.0.0</modelVersion>

  <parent>
    <artifactId>Parent</artifactId>
    <groupId>com.domain</groupId>
    <version>1.0-SNAPSHOT</version><!-- must hard code this -->
  </parent>

  <!--groupId>com.domain</groupId--><!-- you can skip this, you inherit it -->
  <artifactId>Child3</artifactId>
  <packaging>war</packaging>

  <name>Child3</name>

  <dependencies>
    <dependency>
      <groupId>${project.groupId}</groupId>
      <artifactId>Child1</artifactId>
      <version>${project.version}</version>
    </dependency>
    <dependency>
      <groupId>${project.groupId}</groupId>
      <artifactId>Child2</artifactId>
      <version>${project.version}</version>
    </dependency>
  </dependencies>
</project>

As I wrote, I don't think using dependencyManagement is really useful for internal dependencies and that's how I setup my projects. But you can if you want. Just use the properties to not repeat information.

Pascal Thivent
The problem really came from the use of RELEASE as version number. Merci Pascal.
Damien