maven-dependency-plugin icon indicating copy to clipboard operation
maven-dependency-plugin copied to clipboard

Understand hamcrest-core 2.x

Open elharo opened this issue 5 months ago • 3 comments

Affected version

HEAD

Bug description

    <dependency>
      <groupId>org.hamcrest</groupId>
      <artifactId>hamcrest-core</artifactId>
      <version>2.2</version>
      <scope>test</scope>
    </dependency>

This one's an ugly mess. It has a purpose when present to avoid introducing a transitive dependency on hamcrest-core 1.3, which can happen with JUnit 4. However, it's just a shim that contains no classes and depends on hamcrest.

This creates one of the ugly unused when included and needed when not included warning Catch-22s.

In any case we should never report hamcrest-core 2.2 as unused. It contains nothing, causes no problems, and prevents other problems even though it contributes exactly zero classes to the classpath.

elharo avatar Oct 04 '25 21:10 elharo

@slawekjaranowski notes that "Instead of using it you can exclude hamcrest-core from junit and then use hamcrest with the newer version". Might (or might not) be possible to note this in the warnings somehow

elharo avatar Oct 05 '25 11:10 elharo

hamcrest moved everything to one artifact, old artifacts are preserved for compatibility.

As you see old artifact contains only dependencies to new one, so should be ok

slawekjaranowski avatar Oct 05 '25 11:10 slawekjaranowski

The problem is not hamcrest itself. It's that when you use it like this you get a warning that it's unused. Then you remove it and get a warning that it's declared but not used. You have to use the exclusion you suggested to prevent both warnings from appearing. The dependency plugin doesn't understand what's going on here.

elharo avatar Oct 05 '25 11:10 elharo