Prevent dependency version overrides in Maven child pom

I have a dependencyManagement section in the parent pom like

<dependencyManagement> <dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpclient</artifactId> <version>4.2.1</version> </dependency> </dependencyManagement> 

and child pom having it

 <dependencies> <dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpclient</artifactId> <version>4.0</version> </dependency> </dependencies> 

I tried to prevent such an override in child pops using the executor plugin , allowing them to be installed only in the parent, but haven failed. I would like this not to be possible to build. Is this possible with this plugin or in any other way?

There is a DependencyCovergence , which causes all versions to be the same, but too restrictive, because I do not want to control all transitive dependencies - only those that are explicitly defined.

I would be glad if I could simply prohibit introducing any new dependencies at all into children's pumps - everything that needs to be defined must be defined in the parent pump, and then it was simply mentioned, if necessary, in the child.

+7
source share
1 answer

You can add the dependency: analysis-dep-mgt in the parent pom and configure it to fail if the version does not match :

  <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <version>2.6</version> <executions> <execution> <id>analyze</id> <phase>package</phase> <goals> <goal>analyze-dep-mgt</goal> </goals> <configuration> <failBuild>true</failBuild> <ignoreDirect>false</ignoreDirect> </configuration> </execution> </executions> </plugin> </plugins> </build> 
+10
source

All Articles