Maven排除传递依赖项的传递依赖项 [英] Maven exclude transitive dependency of a transitive dependency

查看:436
本文介绍了Maven排除传递依赖项的传递依赖项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在pom文件中是否有一种语法方法来排除传递性依赖项的依赖项.

Is there a syntactic way in a pom file to exclude a dependency of a transitive dependency.

例如,如果A具有依赖项B,而B具有依赖项C,而C具有D依赖项,则这是在编译A时排除依赖项D的一种方式.

For example, if A has a dependency B and B has a dependency C and C has a dependency on D, a way to exclude dependency D when compiling A.

对依赖项的排除似乎只深入了一层.

Exclusions for a dependency only seem to go one level deep.

我过去如何做到这一点是在A的pom中包含依赖项C,然后在C的依赖项声明中添加对D的排除.这是推荐的方法吗?

How I have accomplished this in the past is to include dependency C in A's pom and then add the exclusion for D in C's dependency declaration. Is this the recommended way?

推荐答案

您可以将D<exclusions>元素添加到A的POM中的依赖项B.排除在递归依赖项上递归工作.

You can add an <exclusions> element for D to the dependency B in the POM of A. Exclusions work recursively on transitive dependencies.

对复杂项目执行此操作的一种好方法是在父POM中使用<dependencyManagement>元素,该元素会排除您不想在任何地方看到的任何内容.

A good way to do this for a complex project is to use an <dependencyManagement> element in the parent POM which excludes anything you don't want to see anywhere.

这篇关于Maven排除传递依赖项的传递依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆