maven icon indicating copy to clipboard operation
maven copied to clipboard

Let define a dependency version globally outside of a pom.xml file

Open manueljordan opened this issue 1 month ago • 2 comments

New feature, improvement proposal

Hello Maven Team

Pls consider the following scenario:

Exists many projects with the same dependency such as JUnit. These projects are not related among them and as reminder they are of the two following types:

Standalone projects

Such as project-a, project-b, ..., project-n where is used:

  • <packaging>jar</packaging>

Parent/module projects

Such as parent-project-001, parent-project-002, ..., parent-project-00n where is used:

  • <packaging>pom</packaging> + <packaging>jar</packaging>

Because they are not related among them and if exists a new version of JUnit is mandatory open each project and upgrade the version at the pom.xml file. It such as:

<properties>
 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
 <jdk.version>25</jdk.version>
  ...
 <junit.version>6.1.3</junit.version>
</properties>

...

<dependency>
 <groupId>org.junit.jupiter</groupId>
 <artifactId>junit-jupiter-engine</artifactId>
 <version>${junit.version}</version>
 <scope>test</scope>
</dependency>

As you can imagine it can be "complicated"

Suggestion

Can be possible do it globally? It to be declared for example at the /home/<username>/apache/maven/<version>/conf/settings.xml file or something special such as the /home/<username>/apache/maven/<version>/properties/properties.xml file which would contain:.

<global-properties>
 <junit.version>6.1.3</junit.version>
</global-properties>

It to be applied as:

<properties>
 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
 <jdk.version>25</jdk.version>
  ...
 <junit.version>${global.property.junit.version}</junit.version>
</properties>

...

<dependency>
 <groupId>org.junit.jupiter</groupId>
 <artifactId>junit-jupiter-engine</artifactId>
 <version>${junit.version}</version>
 <scope>test</scope>
</dependency>

I hope you see my point

Of course if is not need it the use of the global approach then is used the classic way as the 1rst sample code shown (practically it becomes now a kind of override of the global approach)

Thanks for your understanding

Just in case: pls, consider to create the discussions section as Apache Netbeans has

manueljordan avatar Oct 05 '26 21:10 manueljordan

I noticed that Maven already supports injecting properties from an active profile in settings.xml into a project's POM. Would it be useful to extend the existing documentation with an example demonstrating how this can be used to manage dependency versions globally? I'd be interested in contributing that documentation improvement.

codewithsinchana avatar Nov 04 '26 15:11 codewithsinchana

Thanks for the reply

I noticed that Maven already supports injecting properties from an active profile in settings.xml into a project's POM

How did you realize about that?

Would it be useful to extend the existing documentation with an example demonstrating how this can be used to manage dependency versions globally

If your discovery resolves my request has a lot of sense your proposition

I'd be interested in contributing that documentation improvement.

It is your own decision.

Big thanks!!!

manueljordan avatar Nov 04 '26 17:11 manueljordan