javamaven

org.apache.maven.plugins.enforcer.RequireUpperBoundDeps failed with message:


When I run mvn clean install I got those errors, what's the correct way to fix this issue? I tried to change the version of junit-jupiter to 5.7.0 but it causes more errors, can anyone help me with that?

[WARNING] Rule 1: org.apache.maven.plugins.enforcer.RequireUpperBoundDeps failed with message:
Failed while enforcing RequireUpperBoundDeps. The error(s) are [
Require upper bound dependencies error for org.junit.jupiter:junit-jupiter-api:5.5.2 paths to dependency are:
+-my-service:1.0.0-SNAPSHOT
  +-org.junit.jupiter:junit-jupiter-api:5.5.2
and
+-my-service:1.0.0-SNAPSHOT
  +-org.junit.jupiter:junit-jupiter-engine:5.5.2
    +-org.junit.jupiter:junit-jupiter-api:5.5.2
and
+-my-service:1.0.0-SNAPSHOT
  +-org.springframework.boot:spring-boot-starter-test:2.4.1
    +-org.junit.jupiter:junit-jupiter:5.7.0
      +-org.junit.jupiter:junit-jupiter-api:5.5.2 (managed) <-- org.junit.jupiter:junit-jupiter-api:5.7.0
and
+-my-service:1.0.0-SNAPSHOT
  +-org.springframework.boot:spring-boot-starter-test:2.4.1
    +-org.mockito:mockito-junit-jupiter:3.6.28
      +-org.junit.jupiter:junit-jupiter-api:5.5.2 (managed) <-- org.junit.jupiter:junit-jupiter-api:5.4.2
and
+-my-service:1.0.0-SNAPSHOT
  +-org.springframework.boot:spring-boot-starter-test:2.4.1
    +-org.junit.jupiter:junit-jupiter:5.7.0
      +-org.junit.jupiter:junit-jupiter-params:5.7.0
        +-org.junit.jupiter:junit-jupiter-api:5.5.2 (managed) <-- org.junit.jupiter:junit-jupiter-api:5.7.0

Solution

  • The rule seems to enforce a common upper bounds for a set of dependencies: this may be used to achieve binary compatibility (eg: to ensure that you don't use a lower version that would be incompatible with a transitive dependency you use because its version would be greater).

    [WARNING] Rule 1: org.apache.maven.plugins.enforcer.RequireUpperBoundDeps failed with message:
    Failed while enforcing RequireUpperBoundDeps. The error(s) are [
    Require upper bound dependencies error for org.junit.jupiter:junit-jupiter-api:5.5.2 paths to dependency are:
    +-my-service:1.0.0-SNAPSHOT
      +-org.junit.jupiter:junit-jupiter-api:5.5.2
    and
    +-my-service:1.0.0-SNAPSHOT
      +-org.junit.jupiter:junit-jupiter-engine:5.5.2
        +-org.junit.jupiter:junit-jupiter-api:5.5.2
    and
    +-my-service:1.0.0-SNAPSHOT
      +-org.springframework.boot:spring-boot-starter-test:2.4.1
        +-org.junit.jupiter:junit-jupiter:5.7.0
          +-org.junit.jupiter:junit-jupiter-api:5.5.2 (managed) <-- org.junit.jupiter:junit-jupiter-api:5.7.0
    

    spring boot is importing junit at version 5.7.0, but you have specified junit 5.5.2.

    Try to use the highest version (eg: 5.7.0).