Maven is a widely used software development tool used in Java-based applications. Maven is commonly used in spring boot applications. The “Overriding Managed Version” warning message is shown in the maven when a new dependency is created in the pom.xml file. As this is a warning message, the developers will mostly ignore it.

This “Overriding Managed Version” warning message can be resolved with a simple step in the pom.xml file. Although this warning message is harmless, it becomes a blocker for building applications in the case of multi-module applications that are highly complex. In this post, we’ll see what this warning message is and how this warning message can be resolved.

The warning message is going to be like the one below.

Overriding managed version 3.9 for commons-lang3


Root Cause

Maven build framework supports the development of multi-module projects. There is a maven main project. One or more maven modules will be created for the main project. The dependent packages are created in the main project. Such dependent packages can be included in maven modules. The main project maintains the dependency in <dependencymanagement> tag.

The dependency version is maintained in the main maven project. In any of the maven modules that use this dependency for a different version, this warning message will be displayed in the eclipse Problems window.

Users are trying to compile or develop a maven module project using a different version of the suggested dependency package. In this case, the compilation may have been successful with the overridden version, and may have failed while running the application.



How to reproduce this warning message

The first step is to create a maven main project with a dependency in the < dependency management > section. Create one or more sub-maven module projects. Use the same dependency with different versions. The version of the main maven project and the module projects are different. This illustrates how the module project tries to override the version that is built in the main maven project.

The following example will illustrate how to replicate this warning message. The “commons-lang3” dependency is enabled with version 3.9.1.

pom.xml (child / module )

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>2.2.5.RELEASE</version>
		<relativePath /> <!-- lookup parent from repository -->
	</parent>
	<groupId>com.yawintutor</groupId>
	<artifactId>Spring-Application</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<name>SpringBootJsonbSimple</name>
	<description>Spring Boot Project</description>

	<properties>
		<java.version>1.8</java.version>
	</properties>

	<dependencies>
		<dependency>
			<groupId>org.apache.commons</groupId>
			<artifactId>commons-lang3</artifactId>
			<version>3.9.1</version>
		</dependency>
	</dependencies>

	<build>
		<plugins>
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
			</plugin>
		</plugins>
	</build>

</project>

The parent project pom.xml requires the dependency “commons-lang3.” The code below shows that the dependency “commons-lang3” is attached to the parent pom.xml within the dependency management tag. Commons-lang3 is configured for version 3.9.

pom.xml (parent maven project)

<?xml version="1.0" encoding="utf-8"?><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-dependencies</artifactId>
    <version>2.2.5.RELEASE</version>
    <relativePath>../../spring-boot-dependencies</relativePath>
  </parent>

   <properties>
    <commons-lang3.version>3.9</commons-lang3.version>
   </properties>

  <dependencyManagement>
     <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-lang3</artifactId>
        <version>${commons-lang3.version}</version>
      </dependency>
 </dependencyManagement>
 
   ...........
   ...........
<?xm/>


Solution 1

The dependency versions are configured and maintained in the main maven project. The version is not expected to configured in the module projects. Remove the tag in the dependency in the main module projects. By default, maven must take the version from the main maven project.

The full pom.xml file is shown in the code below after removing < version>. Dependency uses the version of the main maven project.

pom.xml (child / module)

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>2.2.5.RELEASE</version>
		<relativePath /> <!-- lookup parent from repository -->
	</parent>
	<groupId>com.yawintutor</groupId>
	<artifactId>Spring-Application</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<name>SpringBootJsonbSimple</name>
	<description>Spring Boot Project</description>

	<properties>
		<java.version>1.8</java.version>
	</properties>

	<dependencies>
		<dependency>
			<groupId>org.apache.commons</groupId>
			<artifactId>commons-lang3</artifactId>
		</dependency>
	</dependencies>

	<build>
		<plugins>
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
			</plugin>
		</plugins>
	</build>

</project>


Solution 2

Sometimes the maven project requires a change in the version of the dependency files. In this case, the dependency version of the main maven project should be updated and removed from the project module. As the version is updated in the main maven project, the new version is reflected in all maven module projects.

Remove the <version> tag in module maven project pom.xml file.

pom.xml (child /module)

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>2.2.5.RELEASE</version>
		<relativePath /> <!-- lookup parent from repository -->
	</parent>
	<groupId>com.yawintutor</groupId>
	<artifactId>Spring-Application</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<name>SpringBootJsonbSimple</name>
	<description>Spring Boot Project</description>

	<properties>
		<java.version>1.8</java.version>
	</properties>

	<dependencies>
		<dependency>
			<groupId>org.apache.commons</groupId>
			<artifactId>commons-lang3</artifactId>
		</dependency>
	</dependencies>

	<build>
		<plugins>
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
			</plugin>
		</plugins>
	</build>

</project>

Change the dependency version of the < properties > tag in the main maven project. The < commons-lang3.version > tag is modified to 3.9.1.

pom.xml (main maven project)

<?xml version="1.0" encoding="utf-8"?><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-dependencies</artifactId>
    <version>2.2.5.RELEASE</version>
    <relativePath>../../spring-boot-dependencies</relativePath>
  </parent>

   <properties>
    <commons-lang3.version>3.9.1</commons-lang3.version>
   </properties>

  <dependencyManagement>
     <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-lang3</artifactId>
        <version>${commons-lang3.version}</version>
      </dependency>
 </dependencyManagement>
 
   ...........
   ...........
<?xm/>


Solution 3

In some instances, it is not harm to modify the dependency version only in maven module projects. If the version is modified in the main maven project, it will cause a lot of dependency issues in other maven module projects.

In this case, remove the < version > tag in the dependency configuration. Add a new version of the < property > tag to the pom.xml module file. The code below includes the < commons-lang3.version > tag in the pom.xml module file.

pom.xml (child / module)

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>2.2.5.RELEASE</version>
		<relativePath /> <!-- lookup parent from repository -->
	</parent>
	<groupId>com.yawintutor</groupId>
	<artifactId>Spring-Application</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<name>SpringBootJsonbSimple</name>
	<description>Spring Boot Project</description>

	<properties>
		<java.version>1.8</java.version>
		<commons-lang3.version>3.9.1</commons-lang3.version>
	</properties>

	<dependencies>
		<dependency>
			<groupId>org.apache.commons</groupId>
			<artifactId>commons-lang3</artifactId>
		</dependency>
	</dependencies>

	<build>
		<plugins>
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
			</plugin>
		</plugins>
	</build>

</project>



Leave a Reply