从Maven中的依赖项中排除类 [英] Exclude classes from a dependency in Maven

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

问题描述

我有一个项目依赖于供应商控制的工件。此工件包含一些我依赖的类,以及一些较旧且导致问题的类。有没有办法让maven自动扩展jar,删除类,并将它们重新打包为依赖?我将尝试举例。

I have a project which depends on an artifact which is controlled by a supplier. This artifact contains some classes that I depend on, and some which are older and causing problems. Is there a way to get maven to automatically expand a jar, remove classes, and re-package them as a dependency? I'll try to give an example.

supplier:artifact:1.0.0
com.supplier.useful.ClassA
com.supplier.dto.ClassB (old)

us:dependency:1.1.20
com.supplier.dto.ClassB (new)

us:project-web:1.1.20
- supplier:artifact:1.0.0
- us:dependency:1.1.20

所以 - 我需要在project-web中使用 ClassA ,但我需要使用 ClassB 来自依赖工件。我无法修改供应商:工件,或我们:依赖。

So - I need to use ClassA in project-web, but I need to use the ClassB from the dependency artifact. I can't modify supplier:artifact, or us:dependency.

任何想法?!

推荐答案

由于版本2.0.9 maven保留了类路径排序,因此如果您在jar中定义修补类,那么在供应商jar之前它将隐藏供应商实现。

Since version 2.0.9 maven preserves the classpath ordering so if you define your patched classes in a jar BEFORE the supplier jar it will hide the supplier implementation.

或者您可以查看 maven shade插件,因为它可以正如你所说的那样。

Alternatively you can look at the maven shade plugin as it does exactly what you are asking according to me.

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

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