Reputation: 1756
I have a multipom maven proyect. In my pom root, I have a parent pom and DependencyManagement with spring dependencies.
<?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>
<groupId>com.company.project</groupId>
<artifactId>artifactId</artifactId>
<version>${project-version}</version>
<packaging>pom</packaging>
<!-- Parent Pom -->
<parent>
<groupId>com.company.project</groupId>
<artifactId>parent_pom</artifactId>
<version>1.0.0</version>
</parent>
<modules>
<module>artifactId-war</module>
</modules>
<properties>
<project-version>1.0.0</project-version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<spring.version>4.3.3.RELEASE</spring.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-framework-bom</artifactId>
<version>${spring.version}</version>
<type>pom</type> -->
<scope>import</scope>
</dependency>
....
In my artifactId-war, I have this pom.xml:
<?xml version="1.0"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>com.company.project</groupId>
<artifactId>artifactId-war</artifactId>
<packaging>war</packaging>
<parent>
<groupId>com.company.project</groupId>
<artifactId>artifactId</artifactId>
<version>${project-version}</version>
</parent>
<dependencies>
<!-- Spring -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
</dependency>
...
My problem is that in the parent pom there is an spring old version(4.1.8) and in my root pom I use 4.3.3 version with the artifact spring-framework-bom. In my dependency list proyect appears parent_pom versions. How I can give preference to the dependencies of my pom root?
Upvotes: 0
Views: 947
Reputation: 3799
Your artifactId-war's pom.xml has a mistake.
in the <parent>
tag, the <groupId>
should be com.company.project
instead of com.company.project.artifactId
.
With this, you don't have to specifically mention the spring jar version (as suggested by the other answer) in the artifactId-war's pom.xml. It will inherit the version from the artifactId's pom.xml.
It is always a good practice to maintain the dependency versions from the parent pom as against maintaining the versions at the child pom level. Your child pom should only contain the groupId and the artifactId of the dependency you want. Its version will be handled by the parent pom.
Upvotes: 0
Reputation: 2237
You can declare the correct spring dependency in your artifactId-war pom. Maven resolves conflicts by the shortest path winner rule.
If you just want to have a overall control through the parent pom, you can have a property defined in your parent, but you still have to declare a dependency in you artifactId-war pom.
Upvotes: 0