Micrometer-observation-test Brings Unnecessary JUnit Dependencies, Leading To Conflicts

by ADMIN 88 views

micrometer-observation-test brings unnecessary JUnit dependencies, leading to conflicts

The micrometer-observation-test library has a broad dependency on JUnit, which can lead to unnecessary dependencies being brought into a project. This can cause conflicts and issues, especially when working with multiple versions of JUnit. In this article, we will explore the issue and provide a solution to fix it.

The micrometer-observation-test library has a dependency on JUnit, which is specified in the build.gradle file as follows:

api 'org.junit.jupiter:junit-jupiter:5.12.0'

This dependency is too broad and brings in a number of unnecessary dependencies, including:

  • org.junit:junit-bom:5.12.0
  • org.junit.jupiter:junit-jupiter-api:5.12.0
  • org.junit.jupiter:junit-jupiter-params:5.12.0
  • org.junit.jupiter:junit-jupiter-engine:5.12.0
  • org.junit.platform:junit-platform-commons:1.12.0
  • org.junit.platform:junit-platform-engine:1.12.0
  • net.bytebuddy:byte-buddy:1.14.11
  • org.opentest4j:opentest4j:1.3.0

These dependencies can cause conflicts and issues, especially when working with multiple versions of JUnit.

When a project that uses JUnit 5.11.0 is added to the test scope, the tests fail with the following error:

>  OutputDirectoryProvider not available; probably due to unaligned versions of the junit-platform-engine and junit-platform-launcher jars

This issue can be reproduced on the Spring-WS project in a feature branch.

To fix the issue, we can exclude the JUnit dependency from the micrometer-observation-test library. We can do this by adding the following configuration to the build.gradle file:

testImplementation("io.micrometer:micrometer-observation-test") {
    exclude(group: "org.junit.jupiter")
}

This will exclude the JUnit dependency from the micrometer-observation-test library, and the tests should run without any issues.

In conclusion, the micrometer-observation-test library has a broad dependency on JUnit, which can lead to unnecessary dependencies being brought into a project. This can cause conflicts and issues, especially when working with multiple versions of JUnit. By excluding the JUnit dependency from the micrometer-observation-test library, we can fix the issue and ensure that our tests run without any problems.

  • The issue was reported by @wilkinsona.
  • The Spring-WS project is affected by this issue, and a feature branch has been created to reproduce the issue.
  • The solution was provided by @wilkinsona.

In our previous article, we discussed the issue of the micrometer-observation-test library bringing unnecessary JUnit dependencies, leading to conflicts. In this article, we will provide a Q&A section to answer some of the most frequently asked questions about this issue.

A: The micrometer-observation-test library has a broad dependency on JUnit, which can lead to unnecessary dependencies being brought into a project. This can cause conflicts and issues, especially when working with multiple versions of JUnit.

A: The micrometer-observation-test library brings in a number of unnecessary dependencies, including:

  • org.junit:junit-bom:5.12.0
  • org.junit.jupiter:junit-jupiter-api:5.12.0
  • org.junit.jupiter:junit-jupiter-params:5.12.0
  • org.junit.jupiter:junit-jupiter-engine:5.12.0
  • org.junit.platform:junit-platform-commons:1.12.0
  • org.junit.platform:junit-platform-engine:1.12.0
  • net.bytebuddy:byte-buddy:1.14.11
  • org.opentest4j:opentest4j:1.3.0

A: These unnecessary dependencies can cause conflicts and issues, especially when working with multiple versions of JUnit. This can lead to errors and failures in the build process.

A: To fix the issue, you can exclude the JUnit dependency from the micrometer-observation-test library. You can do this by adding the following configuration to the build.gradle file:

testImplementation("io.micrometer:micrometer-observation-test") {
    exclude(group: "org.junit.jupiter")
}

A: If you're using a different version of JUnit, you may need to adjust the configuration to exclude the correct version of JUnit. You can do this by specifying the version of JUnit in the exclude configuration:

testImplementation("io.micrometer:micrometer-observation-test") {
    exclude(group: "org.junit.jupiter", module: "junit-jupiter-api:5.11.0")
}

A: Yes, you can use a different testing framework instead of JUnit. However, you will need to adjust the configuration to exclude the JUnit dependency and include the dependency for the new testing framework.

A: If you're using a different build tool, such as Maven, you will need to adjust the configuration to exclude the JUnit dependency and include the dependency for the new testing framework. You can do this by adding the following configuration to the pom.xml file:

<dependency>
    <groupId>io.micrometer</groupId>
    <artifactId>micrometer-observation-test</artifactId>
    <exclusions>
        <exclusion>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-api</artifactId>
        </exclusion>
    </exclusions>
</dependency>

In conclusion, the micrometer-observation-test library has a broad dependency on JUnit, which can lead to unnecessary dependencies being brought into a project. By excluding the JUnit dependency, you can fix the issue and ensure that your tests run without any problems.