Is there a way to exclude a Maven dependency globally?

后端 未结 4 476
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-30 20:53

I’m trying to find a “generic” way of excluding a transitive dependency from being included without having to exclude it from all the dependencies that depend on it. For ex

4条回答
  •  北海茫月
    2020-11-30 21:19

    As a reminder, here is the answer from Maven official documentation:

    Why exclusions are made on a per-dependency basis, rather than at the POM level

    This is mainly done to be sure the dependency graph is predictable, and to keep inheritance effects from excluding a dependency that should not be excluded. If you get to the method of last resort and have to put in an exclusion, you should be absolutely certain which of your dependencies is bringing in that unwanted transitive dependency.

    If one wants to make a build more robust, a version range can be used. This would ensure that no newer version of the dependency can interfere with the project.

    
       org.slf4j
       slf4j-api
       [1.4.2,)
       provided
    
    

    Any slf4j-api version >= 1.4.2 will be considered as offered (provided) at runtime, either from a configured classpath or a container.

    References

    • Maven version range
    • Optional Dependencies and Dependency Exclusions

提交回复
热议问题