Maven dependency: exclude one class

烂漫一生 提交于 2019-12-12 07:26:11

问题


For example I have dependency:

<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-api</artifactId>
    <version>1.5.6</version>
</dependency>  

Can I exclude one class, for example org/slf4j/Marker.class?


回答1:


Try it with the shade plugin

Details on why use shade and basic usage




回答2:


Excluding a single class in not possible. Within <dependency> tags you can define <exclusions/>. However, these are for entire dependencies.

The shade plugin should be handled with care. Generally, it's not good practice to be creating a jar containing all your dependencies in one place as it tends to lead to problems if you are to be using the produced artifact in another project as a dependency. For example, shading slf4j in your jar and then depending on your artifact in another project where you have another slf4j will bring you grief.




回答3:


You could change those classes and define them in a different jar/module which should be included as a dependency before the jar that supplies the dependency where your class to be excluded resides (Marker.class).

Maven remembers the classpath ordering from version 2.0.9.



来源:https://stackoverflow.com/questions/10086262/maven-dependency-exclude-one-class

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!