Let's say there is a root project A with child project B. Projects A and B have the same version, let's say 1. And there is a separate root project X with child project Y. Projects X and Y also have the same version, let's say 2.
I want to:
- include project A as parent project of project X.
- include project B as a dependency in the project Y.
This is how I do this:
pom.xml, project X:
<groupId>projectX</groupId>
<artifactId>X</artifactId>
<version>2</version>
<parent> <!-- Project A defines a lot of dependencies that I don't want to redefine in project B -->
<groupId>projectA</groupId>
<artifactId>A</artifactId>
<version>1</version>
</parent>
...
<properties>
<!-- I'm duplicating version 1 here -
I have to define it above, in project's
version and define it again in all the places
where I refer to children projects of the
root project A -->
<projectA.version>1</projectA.version>
</properties>
...
<dependencyManagement>
<dependencies>
<dependency>
<groupId>projectA</groupId>
<artifactId>B</artifactId>
<version>${projectA.version}</version>
</dependency>
...
and pom.xml, project Y:
<parent>
<groupId>projectX</groupId>
<artifactId>X</artifactId>
<version>2</version>
</parent>
<dependencies>
<dependency>
<groupId>projectA</groupId>
<artifactId>B</artifactId>
</dependency>
...
I felt that duplication of version entry (which is 1 in the example given above) does not look very elegant and I tried to use property placeholders like parent.version and project.parent.version but none worked for me - apparently parent.version and project.parent.version are overridden in the children projects of X so maven thinks they are 2, not 1.
The question is whether it is possible to somehow refer to the parent project's version if current root project uses another version than parent project.
I hope the question makes sense as it looks a bit confusing and I don't know how to make it simpler.
I suspect that it is not possible to do what I want by design but I hope that someone with significant maven experience can confirm that.