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

查看:30
本文介绍了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 添加一个 元素到依赖BA 的 POM 中.排除在传递依赖项上递归工作.

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天全站免登陆