Home > Back-end >  How to make specific maven dependency versions mandatory
How to make specific maven dependency versions mandatory

Time:05-23

I am working on creating a common library for my team which can be used by different micro-services of our team. Common library will be service-starter which includes : specific spring boot, spring version and other compatible versions and dependencies. Is it possible to guardrail using maven such that our whole team must be on specific MUST versions of some maven dependencies like spring boot version should be common across team (We will also have other maven dependencies which can be overridden in respective micro-service pom if needed.)

CodePudding user response:

You cannot stop your team from defining their own version in their project. However, you can add a <dependencyManagement>tag in your project which will define the versions you wish them to use so they won't have to decide. But, again, nothing to stop them to override these.

CodePudding user response:

You can create a parent pom that you want and put in <dependencyManagement> the dependencies that you want to be used by applications that use this parent pom.

<dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>group-a</groupId>
        <artifactId>artifact-a</artifactId>
        <version>1.0</version>
      </dependency>
    </dependencies>
</dependencyManagement>

so if another application uses as parent pom the one you have declared above and uses as dependency

<dependencies>
  <dependency>
    <groupId>group-a</groupId>
    <artifactId>artifact-a</artifactId>
  </dependency>
</dependencies>

(It does not contain any specific version), it would retrieve by default the version which was delcared in parent pom of 1.0

But the child pom application would always be free to declare their own version if they want, and use that instead, effectively overriding what was declared in parent pom

  <dependencies>
      <dependency>
        <groupId>group-a</groupId>
        <artifactId>artifact-a</artifactId>
        <version>1.2</version>
      </dependency>
    </dependencies>

More about Dependency management in Maven

  • Related