Rafael Lima
Rafael Lima

Reputation: 3535

How to make dependencies version option on inherited pom

My question is very simple:

When i'm creating a maven project if i chose to make my pom inherit from

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.7.2</version> 
</parent>

for all dependencies I include, if it is included in the parent's pom i dont need to specify which version i'm using in the inherited pom.

That is an amazing thing and avoid using multiple versions of same library.

the question is, HOW TO ACHIEVE THIS BEHAVIOR

I've a parent pom for my projects, but when I extend it, the childs pom still need to specify each dependency version evem thought it is specified in the parents pom... this causes me the need to update dependencies version multiple places everytime one dependency changed it's version

I end up by doing somthing like (child pom):

<dependency>
    <groupId>br.com.fisgar</groupId>
    <artifactId>fisgar-model</artifactId>
    <version>${project.version}</version>
</dependency>

but i would like to make possible omit the version as a whole, same way as the spring dependency.

how can i do that

Upvotes: -2

Views: 64

Answers (1)

Oleg Cherednik
Oleg Cherednik

Reputation: 18245

In the parent.pom add dependency with version to <dependencyManagement> section. In this case, in the child.pom you will be able to add this dependency without version.

You can get more details in the official documentation Introduction to the Dependency Mechanism

Upvotes: 1

Related Questions