Search code examples
javamavenparent-childpom.xmldependency-management

Maven sibling module dependency without specifying the version


I have a multi-module maven application with below dependencies; we are using maven release plugin for one of the modules and its version is auto-incremented by every release build.

Parent module
   |---Module A
   |---Module B - version is auto incremented by maven release plugin
   |---Module C - has a dependency on module B

Question: How to add dependency of Module B in Module C, without specifying the version. Currently, I am hard-coding the version but after every release I have to manually update the version to latest. Just to be clear, I want to have a dependency as below.

    <dependency>
        <groupId>com.my.application</groupId>
        <artifactId>Module B</artifactId>
    </dependency>

I tried using, project.version, but it gives the parent version and of no help. I tried using dependencymanagement but could not get it working. Please suggest. Thanks.


Solution

  • Define your version as an open ended version range as below. This will pick the latest available.

    <version>[1.2.3,)</version>

    But, make sure your Module B's versioning follows the standard.