Hamcrest Matcher signer information does not match signer information of other classes in the same package
Asked Answered
D

5

6

I'm trying to write some integration tests in my Spring Boot application using REST-Assured and JUnit5 but when I run the following:

@SpringBootTest(classes = ProductsApplication.class)
class ProductsApiTest {

  @Before
  public void setup() {
    RestAssured.baseURI = "http://localhost:8080/test/api/products";
  }

  @Test
  public void test1() {
    ValidatableResponse statusCode = given().when().get().then().statusCode(200);
  }
}

A nasty error comes up:

java.lang.SecurityException: class "org.hamcrest.Matchers"'s signer information does not match signer information of other classes in the same package

Please take a look at my pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.4.RELEASE</version>
        <relativePath /> <!-- lookup parent from repository -->
    </parent>

    ...
    <dependencies>
        ...
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        ...
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>   
        <dependency>
                    <groupId>org.junit.jupiter</groupId>
                    <artifactId>junit-jupiter-engine</artifactId>
                    <scope>test</scope>
        </dependency>
        <dependency>
                    <groupId>org.junit.platform</groupId>
                    <artifactId>junit-platform-runner</artifactId>
                    <scope>test</scope>
        </dependency>

            ...
        <!-- https://mvnrepository.com/artifact/io.rest-assured/rest-assured -->
        <dependency>
            <groupId>io.rest-assured</groupId>
            <artifactId>rest-assured</artifactId>
        </dependency>
    </dependencies>

    <build>
        ...
    </build>
</project>

Here are the Order and Export + the Libraries the Eclipse project uses: enter image description here

enter image description here

How do I set up the Eclipse environment to work with REST-Assured and Hamcrest? Why would this exception be thrown?

Dynamics answered 29/1, 2020 at 9:9 Comment(7)
There are similar questions with accepted answers already: https://mcmap.net/q/156983/-java-securityexception-signer-information-does-not-match https://mcmap.net/q/160216/-signer-information-does-not-matchKezer
is @Before annotation from aspectj or from junit4?Factotum
@SirDiRakaTymurKubai it is from junitDynamics
@Aivaras i've seen the article but dont know what to do when i have both Junit (which includes hamcrest) on the class path and spring boot test in maven (which also includes it). Both need to stay but they both include hamcrest.Dynamics
@StoyanLupov according to your pom.xml you are using junit-jupiter(junit5) butt in your code you have @Before(junit4) annotation instead of @BeforeEach(junit5). I have no idea how you run your tests(what framework used for this junit4 or junit5) and also what are imports in your code exampleFactotum
@StoyanLupov use exclusions in your pom next to dependency definition to exclude any transient ones. More in docs maven.apache.org/guides/introduction/…Kezer
Did you find any solution? It would be really useful to me... Thanks!Hartzel
S
2

I deleted the org.hamcrest.core_1.3.0.v201303031735.jar from my .p2 plugins folder and it worked for me.

  1. I searched for "hamcrest" in "C:\Users\Dell.p2\pool\plugins" folder and found "org.hamcrest.core_1.3.0.v201303031735.jar" there.
  2. I deleted it for this path.
  3. Tried to run the test cases and it got passed with no failure in statusCode() method line.

Please suggest if anyone has a better solution.

Shalom answered 26/2, 2021 at 9:29 Comment(0)
R
0

In my case, the problem was solved by adding an explicit dependency to Hamcrest at the top of the dependency list in my pom.xml:

<dependency>
    <groupId>org.hamcrest</groupId>
    <artifactId>hamcrest</artifactId>
    <scope>test</scope>
</dependency>
Retainer answered 14/7, 2021 at 19:45 Comment(0)
T
0

This issue can also occur within Eclipse plugin development if you define your own dependency on a later version of hamcrest.

I worked around this by removing the hamcrest plugin from the platform definition:

  • Select Windows -> Preferences -> Plugin Development -> Running Platform -> Edit -> Content
  • Filter for "hamcrest"
  • Untick org.hamcrest.core
Tellus answered 10/4, 2022 at 18:53 Comment(0)
L
0

In my case I just removed the Eclipse's JUnit5 library from classpath.

Laster answered 24/11, 2022 at 13:50 Comment(0)
C
0

If you get this error in eclipse the problem is that eclipse already has a hamcrest-core library in its plugins folder which has priority over your maven hamcrest library.

What you can do is overwrite the eclipse one (careful to have the same version with the one you have in your maven repositories folder). I am using hamcrest-core 1.3.

I'll show the steps for MacOS but should be similar on Windows you just need to find the eclipse plugins folder and maven repositories folder on your own machine.

  1. Close Eclipse.
  2. Go to Eclipse plugins folder (on MacOS: ~/.p2/pool/plugins)
  3. Find your hamcrest-core library (for me: org.hamcrest.core_1.3.0.v20180420-1519.jar)
  4. Make a backup so that you can revert it - rename the file with a different extension (ex: org.hamcrest.core_1.3.0.v20180420-1519.bck)
  5. Copy from the maven repositories (on MacOS: ~/.m2/repository) the hamcrest-core library into the plugins folder with the same name (on MacOS: cp ~/.m2/repository/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar org.hamcrest.core_1.3.0.v20180420-1519.jar)
  6. Open Eclipse and run the test, the test should now run correctly.
Cloe answered 18/12, 2022 at 14:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.