"java.lang.NoClassDefFoundError: org/hamcrest/SelfDescribing" when importing wiremock 2.7.1 maven dependency
See original GitHub issueGreetings,
After some research I decided to use wiremock in our project unit tests, which were working and running as expected before including wiremock 2.7.1
in the project’s pom.xml
my current test scope dependencies until now were the following (taken from the project’s BOM file)
<!-- testing dependency versions -->
<junit.version>4.12</junit.version>
<assertj.version>3.4.0</assertj.version>
<equalsverifier.version>2.1.7</equalsverifier.version>
<openpojo.version>0.8.4</openpojo.version>
after including wiremock in the pom.xml
file:
<dependency>
<groupId>com.github.tomakehurst</groupId>
<artifactId>wiremock</artifactId>
<version>2.7.1</version>
</dependency>
all tests ceased to work, no matter which tool I tried to use
- Eclipse Oxygen Release (4.7.0)
- terminal
mvn clean test
the following exception is being thrown:
java.lang.NoClassDefFoundError: org/hamcrest/SelfDescribing
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at org.junit.internal.builders.JUnit4Builder.runnerForClass(JUnit4Builder.java:10)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:33)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createUnfilteredTest(JUnit4TestLoader.java:84)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:70)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:43)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:444)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Caused by: java.lang.ClassNotFoundException: org.hamcrest.SelfDescribing
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 24 more
After inspecting the pom.xml file in wiremock 2.7.1
I think to have found the possible cause of this:
- Wiremock is including it’s own JUnit library, which luckily matches the version I’m using but with the subtle difference that it is excluding
hamcrest-core
:
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>compile</scope>
<exclusions>
<exclusion>
<artifactId>hamcrest-core</artifactId>
<groupId>org.hamcrest</groupId>
</exclusion>
</exclusions>
</dependency>
Questions
Why is wiremock delivering its own JUnit dependency in a<scope>compile</scope>
scope?Andwhy ishamcrest-core
being implicitly excluded from it?
The real question
- How to workaround this?
I’m considering to exclude the junit dependency from my wiremock dependency, but not yet sure what side effects may arise from this.
Any pointers in the right direction are greatly welcome!
Thank you very much in advance.
PS: Removing the wiremock dependency fixes the problem for me. With the obvious downside that then I cannot use it 😃
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:9
JUnit is now an compileOnly/provided dependency and excluded from the standalone JAR in 2.25.0. Hopefully that should resolve this issue.
Thanks, I’ll take a look.