We have a reactor pom whose child modules are versioned independently, ie. child module declares it's own version that is independent of the version of the main pom. There is however a dependency between two child modules. How should be this dependency configured to always use the version that is declared by the actual module of the reactor pom?
I would expect that I can set up dependency management in the root pom and use some implicit properties to determine the version of child modules, but the best such option I can find :
${session.projectDependencyGraph.sortedProjects[0].version}
or simply
${reactorProjects[0].version}
so that the dependency management in the root pom would look like this:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>mygroup</groupId>
<artifactId>mySubmodule</artifactid>
<version>${reactorProjects[0].version}</version>
</dependency>
</dependencies>
</dependencyManagement>
looks unreliable because the reactor order may change when new modules or dependencies are added.
Maybe this usage scenario is discouraged by design and then I would like to know why.
Edit: As is suggested in comments, declaring a global properties with child versions in parent POM may be an option for newer versions of Maven. I would however like to see some analysis with respect to wider consequences like workflow, releasing, directory and repository settings, some plugins usage (e.g. version plugin) etc. For example I think that direct consequence of this approach is that I would have to release parent module whenever any of child modules are released. Although this is doable, it would impact the original idea of having an independent versioning.
I started a thread with this topic on Maven mailing list, I'm posting TL;DR answer here:
My expected solution with implicit properties is generaly not possible because it would get evaluated not only during build but also when using the built artifact as a dependency in other projects and it's evaluation can have unpredictable results then, because the context of implicit properties is completely different. (I'm stupid, I had the same issue already some time ago with ${project.version} property)
Generaly speaking, the question considers only one scenario in one project from one developer point of view. In the mailing list thread there are other points of view that leads to hardcoding the dependency version numbers either in dependency management or in explicit properties even if something else would be possible.