Maven dependency: exclude one class

后端 未结 3 1065
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-18 20:53

For example I have dependency:


    org.slf4j
    slf4j-api
    

        
相关标签:
3条回答
  • 2020-12-18 21:32

    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.

    0 讨论(0)
  • 2020-12-18 21:36

    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.

    0 讨论(0)
  • 2020-12-18 21:40

    Try it with the shade plugin

    Details on why use shade and basic usage

    0 讨论(0)
提交回复
热议问题