问题
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