How do I get Maven to fail when conflicting versions of the same artifact are referenced?

前端 未结 4 1099
鱼传尺愫
鱼传尺愫 2020-12-14 08:36

I\'d like my Maven build to fail if the same artifact is referenced with different versions in my dependency tree. This would seem like a fairly trivial option, but I can\'

4条回答
  •  心在旅途
    2020-12-14 08:54

    The maven-enforcer-plugin has a dependencyConvergence rule which does what you want. Here's an example from the documentation.

    This will cause a build to fail:

      
        
          org.slf4j
          slf4j-jdk14
          1.6.1
        
        
          org.slf4j
          slf4j-nop
          1.6.0
        
        
    

    With this being logged during compilation:

    [ERROR]
    Dependency convergence error for org.slf4j:slf4j-api:1.6.1 paths to dependency are:
    +-org.myorg:my-project:1.0.0-SNAPSHOT
      +-org.slf4j:slf4j-jdk14:1.6.1
        +-org.slf4j:slf4j-api:1.6.1
    and
    +-org.myorg:my-project:1.0.0-SNAPSHOT
      +-org.slf4j:slf4j-nop:1.6.0
        +-org.slf4j:slf4j-api:1.6.0
    

提交回复
热议问题