Maven dependecy mangement artiafctId with ${project.artiafctId}

In my parent child :

<project>
...
<dependencies>
    <dependency>
        <groupId>${parent.groupId}</groupId>
        <artifactId>${parent.artifactId}-war</artifactId>
        <type>war</type>
    </dependency>
</dependencies>
... 
</project>

In my parent :

<project>
...
<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>myproject-war</artifactId>
            <version>${project.version}</version>
            <type>war</type>
        </dependency>
    </dependencies>
</dependencyManagement>
... 
</project>

Just wondering why using (in the parent)

<artifactId>myproject-war</artifactId>

is working and using

<artifactId>${project.artifactId}-war</artifactId>

is not working

[0]  'dependencies.dependency.version' is missing for be.lab:myproject-war:war

Answers


You should think about your setup. Apart from updating to last Maven version (3.1.1)..

 root -- pom.xml
   +--- m1 (pom.xml)
   +--- m2 (pom.xml)
   +--- m3 (pom.xml)

You root (parent) looks like this:

<project ....>
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.soebes.maven.training</groupId>
  <artifactId>parent</artifactId>
  <packaging>pom</packaging>
  <version>1.0.0-SNAPSHOT</version>

  <modules>
    <module>m1</module>
    <module>m2</module>
    <module>m3-war</module>
  </modules>

  ...
</project>

A typical childs looks like ths:

I would suggest to define the dependencies between the child only in the childs like this:

<project ..>

<modelVersion>4.0.0</modelVersion>

<parent>
  <groupId>com.soebes.maven.training</groupId>
  <artifactId>m1</artifactId>
  <version>1.0.0-SNAPSHOT</version>
</parent>

<artifactId>m1</artifactId>

</project>

A child with a dependency to an other child looks like this:

<project ..>

<modelVersion>4.0.0</modelVersion>

<parent>
  <groupId>com.soebes.maven.training</groupId>
  <artifactId>m1</artifactId>
  <version>1.0.0-SNAPSHOT</version>
</parent>

<artifactId>m2</artifactId>

<dependencies>
  <dependency>
    <groupId>${project.group}</groupId>
    <artifactId>m1</artifactId>
    <version>${project.version}</version>
  </dependency>
</dependencies>

</project>

Furthermore the usage of things like ${parent.*} isn't good practice.

And lets have a look at that war module:

<project ..>

<modelVersion>4.0.0</modelVersion>

<parent>
  <groupId>com.soebes.maven.training</groupId>
  <artifactId>m1</artifactId>
  <version>1.0.0-SNAPSHOT</version>
</parent>

<artifactId>m3-war</artifactId>

<dependencies>
  <dependency>
    <groupId>${project.group}</groupId>
    <artifactId>m2</artifactId>
    <version>${project.version}</version>
  </dependency>
</dependencies>

</project>

I would recommend not to use such constructs like <artifactId>${parent.artifactId}-war</artifactId>. Better use in such situations just simply <artifactId>module-war</artifactId> cause it wouldn't save much.


Need Your Help

NodeJS Filesystem Watch throwing event twice or more often

c++ events node.js filesystems inotify

I'm watching the config files of my NodeJS server on Ubuntu using: