java.lang.NoSuchMethodError: org.hamcrest.Matcher.describeMismatch [duplicate] - java

I'm using JUnit-dep 4.10 and Hamcrest 1.3.RC2.
I've created a custom matcher that looks like the following:
public static class MyMatcher extends TypeSafeMatcher<String> {
#Override
protected boolean matchesSafely(String s) {
/* implementation */
}
#Override
public void describeTo(Description description) {
/* implementation */
}
#Override
protected void describeMismatchSafely(String item, Description mismatchDescription) {
/* implementation */
}
}
It works perfectly fine when run from the command line using Ant. But when run from IntelliJ, it fails with:
java.lang.NoSuchMethodError: org.hamcrest.Matcher.describeMismatch(Ljava/lang/Object;Lorg/hamcrest/Description;)V
at org.hamcrest.MatcherAssert.assertThat(MatcherAssert.java:18)
at org.hamcrest.MatcherAssert.assertThat(MatcherAssert.java:8)
at com.netflix.build.MyTest.testmyStuff(MyTest.java:40)
My guess is that it's using the wrong hamcrest.MatcherAssert. How do I find which hamcrest.MatcherAssert it's using (ie which jar file it's using for hamcrest.MatcherAssert)? AFAICT, the only hamcrest jars in my classpath is 1.3.RC2.
Is IntelliJ IDEA using it's own copy of JUnit or Hamcrest?
How do I output the runtime CLASSPATH that IntelliJ is using?

Make sure the hamcrest jar is higher on the import order than your JUnit jar.
JUnit comes with its own org.hamcrest.Matcher class that is probably being used instead.
You can also download and use the junit-dep-4.10.jar instead which is JUnit without the hamcrest classes.
mockito also has the hamcrest classes in it as well, so you may need to move\reorder it as well

This problem also arises when you have mockito-all on your class path, which is already deprecated.
If possible just include mockito-core.
Maven config for mixing junit, mockito and hamcrest:
<dependencies>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
<version>1.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-library</artifactId>
<version>1.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.9.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>

The problem was that the wrong hamcrest.Matcher, not hamcrest.MatcherAssert, class was being used. That was being pulled in from a junit-4.8 dependency one of my dependencies was specifying.
To see what dependencies (and versions) are included from what source while testing, run:
mvn dependency:tree -Dscope=test

The following should be the most correct today. Note, junit 4.11 depends on hamcrest-core, so you shouldn't need to specify that at all, mockito-all cannot be used since it includes (not depends on) hamcrest 1.1
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>1.10.8</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
</exclusion>
</exclusions>
</dependency>

This worked for me after struggling a bit
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
<version>1.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.9.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>

I know this is an old thread but what solved the issue for me was adding the following to my build.gradle files.
As already stated above there is a compatibility issue with mockito-all
Possibly useful post:
testCompile ('junit:junit:4.12') {
exclude group: 'org.hamcrest'
}
testCompile ('org.mockito:mockito-core:1.10.19') {
exclude group: 'org.hamcrest'
}
testCompile 'org.hamcrest:hamcrest-core:1.3'

Try
expect(new ThrowableMessageMatcher(new StringContains(message)))
instead of
expectMessage(message)
You may write a custom ExpectedException or utility method to wrap up the code.

As of July, 2020 the following dependencies in pom.xml worked for me:
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13</version>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest</artifactId>
<version>2.1</version>
</dependency>
With this 4.13 junit library and hamcrest, it uses hamcrest.MatcherAssert when asserting and throws exception-
enter image description here

Despite the fact that this is a very old question
and probably many of the beforementioned ideas solved many problems,
I still want to share the solution with the community that fixed my problem.
I found that the problem was a function called "hasItem"
which I was using to check whether or not a JSON-Array contains a specific item.
In my case I checked for a value of type Long.
And this led to the problem.
Somehow, the Matchers have problems with values of type Long.
(I do not use JUnit or Rest-Assured so much so idk. exactly why,
but I guess that the returned JSON-data does just contain Integers.)
So what I did to actually fix the problem was the following.
Instead of using:
long ID = ...;
...
.then().assertThat()
.body("myArray", hasItem(ID));
you just have to cast to Integer.
So the working code looked like this:
long ID = ...;
...
.then().assertThat()
.body("myArray", hasItem((int) ID));
That's probably not the best solution,
but I just wanted to mention that the exception can also be thrown because of wrong/unknown data types.

I have a gradle project and when my build.gradle dependencies section looks like this:
dependencies {
implementation group: 'org.apache.commons', name: 'commons-lang3', version: '3.8.1'
testImplementation group: 'org.mockito', name: 'mockito-all', version: '1.10.19'
testImplementation 'junit:junit:4.12'
// testCompile group: 'org.mockito', name: 'mockito-core', version: '2.23.4'
compileOnly 'org.projectlombok:lombok:1.18.4'
apt 'org.projectlombok:lombok:1.18.4'
}
it leads to this exception:
java.lang.NoSuchMethodError: org.hamcrest.Matcher.describeMismatch(Ljava/lang/Object;Lorg/hamcrest/Description;)V
at org.hamcrest.MatcherAssert.assertThat(MatcherAssert.java:18)
at org.hamcrest.MatcherAssert.assertThat(MatcherAssert.java:8)
to fix this issue, I've substituted "mockito-all" with "mockito-core".
dependencies {
implementation group: 'org.apache.commons', name: 'commons-lang3', version: '3.8.1'
// testImplementation group: 'org.mockito', name: 'mockito-all', version: '1.10.19'
testImplementation 'junit:junit:4.12'
testCompile group: 'org.mockito', name: 'mockito-core', version: '2.23.4'
compileOnly 'org.projectlombok:lombok:1.18.4'
apt 'org.projectlombok:lombok:1.18.4'
}
The explanation between mockito-all and mockito-core can be found here:
https://solidsoft.wordpress.com/2012/09/11/beyond-the-mockito-refcard-part-3-mockito-core-vs-mockito-all-in-mavengradle-based-projects/
mockito-all.jar besides Mockito itself contains also (as of 1.9.5) two
dependencies: Hamcrest and Objenesis (let’s omit repackaged ASM and
CGLIB for a moment). The reason was to have everything what is needed
inside an one JAR to just put it on a classpath. It can look strange,
but please remember than Mockito development started in times when
pure Ant (without dependency management) was the most popular build
system for Java projects and the all external JARs required by a
project (i.e. our project’s dependencies and their dependencies) had
to be downloaded manually and specified in a build script.
On the other hand mockito-core.jar is just Mockito classes (also with
repackaged ASM and CGLIB). When using it with Maven or Gradle required
dependencies (Hamcrest and Objenesis) are managed by those tools
(downloaded automatically and put on a test classpath). It allows to
override used versions (for example if our projects uses never, but
backward compatible version), but what is more important those
dependencies are not hidden inside mockito-all.jar what allows to
detected possible version incompatibility with dependency analyze
tools. This is much better solution when dependency managed tool is
used in a project.

In my case, I had to exclude an older hamcrest from junit-vintage:
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest</artifactId>
<version>2.1</version>
<scope>test</scope>
</dependency>

This worked for me. No need to exclude anything. I just used mockito-core instead mockito-all
testCompile 'junit:junit:4.12'
testCompile group: 'org.mockito', name: 'mockito-core', version: '3.0.0'
testCompile group: 'org.hamcrest', name: 'hamcrest-library', version: '2.1'

What worked for me was excluding the hamcrest group from the junit test compile.
Here is the code from my build.gradle:
testCompile ('junit:junit:4.11') {
exclude group: 'org.hamcrest'
}
If you're running IntelliJ you may need to run gradle cleanIdea idea clean build to detect the dependencies again.

I know that's not the best answer, but if you can't get the classpath working, this is a plan B solution.
In my test classpath, I added the following interface with a default implementation for the describeMismatch method.
package org.hamcrest;
/**
* PATCH because there's something wrong with the classpath. Hamcrest should be higher than Mockito so that the BaseMatcher
* implements the describeMismatch method, but it doesn't work for me.
*/
public interface Matcher<T> extends SelfDescribing {
boolean matches(Object item);
default void describeMismatch(Object item, Description mismatchDescription) {
mismatchDescription.appendDescriptionOf(this).appendValue(item);
}
#Deprecated
void _dont_implement_Matcher___instead_extend_BaseMatcher_();
}

For jUnit 4.12, the following dependency combination fixed my issue.
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
<version>1.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-library</artifactId>
<version>1.3</version>
<scope>test</scope>
</dependency>

Related

Mockito making valid Junit tests fail [duplicate]

I'm using JUnit-dep 4.10 and Hamcrest 1.3.RC2.
I've created a custom matcher that looks like the following:
public static class MyMatcher extends TypeSafeMatcher<String> {
#Override
protected boolean matchesSafely(String s) {
/* implementation */
}
#Override
public void describeTo(Description description) {
/* implementation */
}
#Override
protected void describeMismatchSafely(String item, Description mismatchDescription) {
/* implementation */
}
}
It works perfectly fine when run from the command line using Ant. But when run from IntelliJ, it fails with:
java.lang.NoSuchMethodError: org.hamcrest.Matcher.describeMismatch(Ljava/lang/Object;Lorg/hamcrest/Description;)V
at org.hamcrest.MatcherAssert.assertThat(MatcherAssert.java:18)
at org.hamcrest.MatcherAssert.assertThat(MatcherAssert.java:8)
at com.netflix.build.MyTest.testmyStuff(MyTest.java:40)
My guess is that it's using the wrong hamcrest.MatcherAssert. How do I find which hamcrest.MatcherAssert it's using (ie which jar file it's using for hamcrest.MatcherAssert)? AFAICT, the only hamcrest jars in my classpath is 1.3.RC2.
Is IntelliJ IDEA using it's own copy of JUnit or Hamcrest?
How do I output the runtime CLASSPATH that IntelliJ is using?
Make sure the hamcrest jar is higher on the import order than your JUnit jar.
JUnit comes with its own org.hamcrest.Matcher class that is probably being used instead.
You can also download and use the junit-dep-4.10.jar instead which is JUnit without the hamcrest classes.
mockito also has the hamcrest classes in it as well, so you may need to move\reorder it as well
This problem also arises when you have mockito-all on your class path, which is already deprecated.
If possible just include mockito-core.
Maven config for mixing junit, mockito and hamcrest:
<dependencies>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
<version>1.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-library</artifactId>
<version>1.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.9.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>
The problem was that the wrong hamcrest.Matcher, not hamcrest.MatcherAssert, class was being used. That was being pulled in from a junit-4.8 dependency one of my dependencies was specifying.
To see what dependencies (and versions) are included from what source while testing, run:
mvn dependency:tree -Dscope=test
The following should be the most correct today. Note, junit 4.11 depends on hamcrest-core, so you shouldn't need to specify that at all, mockito-all cannot be used since it includes (not depends on) hamcrest 1.1
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>1.10.8</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
</exclusion>
</exclusions>
</dependency>
This worked for me after struggling a bit
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
<version>1.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.9.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
I know this is an old thread but what solved the issue for me was adding the following to my build.gradle files.
As already stated above there is a compatibility issue with mockito-all
Possibly useful post:
testCompile ('junit:junit:4.12') {
exclude group: 'org.hamcrest'
}
testCompile ('org.mockito:mockito-core:1.10.19') {
exclude group: 'org.hamcrest'
}
testCompile 'org.hamcrest:hamcrest-core:1.3'
Try
expect(new ThrowableMessageMatcher(new StringContains(message)))
instead of
expectMessage(message)
You may write a custom ExpectedException or utility method to wrap up the code.
As of July, 2020 the following dependencies in pom.xml worked for me:
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13</version>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest</artifactId>
<version>2.1</version>
</dependency>
With this 4.13 junit library and hamcrest, it uses hamcrest.MatcherAssert when asserting and throws exception-
enter image description here
Despite the fact that this is a very old question
and probably many of the beforementioned ideas solved many problems,
I still want to share the solution with the community that fixed my problem.
I found that the problem was a function called "hasItem"
which I was using to check whether or not a JSON-Array contains a specific item.
In my case I checked for a value of type Long.
And this led to the problem.
Somehow, the Matchers have problems with values of type Long.
(I do not use JUnit or Rest-Assured so much so idk. exactly why,
but I guess that the returned JSON-data does just contain Integers.)
So what I did to actually fix the problem was the following.
Instead of using:
long ID = ...;
...
.then().assertThat()
.body("myArray", hasItem(ID));
you just have to cast to Integer.
So the working code looked like this:
long ID = ...;
...
.then().assertThat()
.body("myArray", hasItem((int) ID));
That's probably not the best solution,
but I just wanted to mention that the exception can also be thrown because of wrong/unknown data types.
I have a gradle project and when my build.gradle dependencies section looks like this:
dependencies {
implementation group: 'org.apache.commons', name: 'commons-lang3', version: '3.8.1'
testImplementation group: 'org.mockito', name: 'mockito-all', version: '1.10.19'
testImplementation 'junit:junit:4.12'
// testCompile group: 'org.mockito', name: 'mockito-core', version: '2.23.4'
compileOnly 'org.projectlombok:lombok:1.18.4'
apt 'org.projectlombok:lombok:1.18.4'
}
it leads to this exception:
java.lang.NoSuchMethodError: org.hamcrest.Matcher.describeMismatch(Ljava/lang/Object;Lorg/hamcrest/Description;)V
at org.hamcrest.MatcherAssert.assertThat(MatcherAssert.java:18)
at org.hamcrest.MatcherAssert.assertThat(MatcherAssert.java:8)
to fix this issue, I've substituted "mockito-all" with "mockito-core".
dependencies {
implementation group: 'org.apache.commons', name: 'commons-lang3', version: '3.8.1'
// testImplementation group: 'org.mockito', name: 'mockito-all', version: '1.10.19'
testImplementation 'junit:junit:4.12'
testCompile group: 'org.mockito', name: 'mockito-core', version: '2.23.4'
compileOnly 'org.projectlombok:lombok:1.18.4'
apt 'org.projectlombok:lombok:1.18.4'
}
The explanation between mockito-all and mockito-core can be found here:
https://solidsoft.wordpress.com/2012/09/11/beyond-the-mockito-refcard-part-3-mockito-core-vs-mockito-all-in-mavengradle-based-projects/
mockito-all.jar besides Mockito itself contains also (as of 1.9.5) two
dependencies: Hamcrest and Objenesis (let’s omit repackaged ASM and
CGLIB for a moment). The reason was to have everything what is needed
inside an one JAR to just put it on a classpath. It can look strange,
but please remember than Mockito development started in times when
pure Ant (without dependency management) was the most popular build
system for Java projects and the all external JARs required by a
project (i.e. our project’s dependencies and their dependencies) had
to be downloaded manually and specified in a build script.
On the other hand mockito-core.jar is just Mockito classes (also with
repackaged ASM and CGLIB). When using it with Maven or Gradle required
dependencies (Hamcrest and Objenesis) are managed by those tools
(downloaded automatically and put on a test classpath). It allows to
override used versions (for example if our projects uses never, but
backward compatible version), but what is more important those
dependencies are not hidden inside mockito-all.jar what allows to
detected possible version incompatibility with dependency analyze
tools. This is much better solution when dependency managed tool is
used in a project.
In my case, I had to exclude an older hamcrest from junit-vintage:
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest</artifactId>
<version>2.1</version>
<scope>test</scope>
</dependency>
This worked for me. No need to exclude anything. I just used mockito-core instead mockito-all
testCompile 'junit:junit:4.12'
testCompile group: 'org.mockito', name: 'mockito-core', version: '3.0.0'
testCompile group: 'org.hamcrest', name: 'hamcrest-library', version: '2.1'
What worked for me was excluding the hamcrest group from the junit test compile.
Here is the code from my build.gradle:
testCompile ('junit:junit:4.11') {
exclude group: 'org.hamcrest'
}
If you're running IntelliJ you may need to run gradle cleanIdea idea clean build to detect the dependencies again.
I know that's not the best answer, but if you can't get the classpath working, this is a plan B solution.
In my test classpath, I added the following interface with a default implementation for the describeMismatch method.
package org.hamcrest;
/**
* PATCH because there's something wrong with the classpath. Hamcrest should be higher than Mockito so that the BaseMatcher
* implements the describeMismatch method, but it doesn't work for me.
*/
public interface Matcher<T> extends SelfDescribing {
boolean matches(Object item);
default void describeMismatch(Object item, Description mismatchDescription) {
mismatchDescription.appendDescriptionOf(this).appendValue(item);
}
#Deprecated
void _dont_implement_Matcher___instead_extend_BaseMatcher_();
}
For jUnit 4.12, the following dependency combination fixed my issue.
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
<version>1.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-library</artifactId>
<version>1.3</version>
<scope>test</scope>
</dependency>

CXF 3.1.12 Cannot create a secure XMLInputFactory

I'm getting a "Cannot create a secure XMLInputFactory" error when sending a request with SoapUI, i tried some of the stackoverflow mentioned solutions like adding woodstox and stax2-api, but the issue persists
from build.gradle:
compile 'org.codehaus.woodstox:woodstox-core-asl:4.4.1'
compile 'org.codehaus.woodstox:stax2-api:4.0.0'
compile 'org.apache.cxf:cxf-rt-frontend-jaxws:3.1.12'
compile 'org.apache.cxf:cxf-rt-ws-security:3.1.12'
compile 'org.apache.cxf:cxf-rt-transports-http:3.1.12'
it was working before with woodstox-core, but started to throw the error
compile 'com.fasterxml.woodstox:woodstox-core:5.0.3'
from previous solutions from version 3 CXF does not even require woodstox, i tried also without woodstox.
Could it be any other dependency updated like axis2?
What should be my next steps to find out? thanks
Note: using tomcat 8.5.19
So solution found, at SaxUtils.java as someone mentioned there is a
factory = XMLInputFactory.newInstance();
Where we can see from where it is loaded.
There was actually a conflict in axis2 so by excluding neethi
compile('org.apache.axis2:axis2-transport-http:1.5.1') {
exclude group: 'javax.servlet', module: 'servlet-api'
exclude module: 'XmlSchema'
exclude group: 'org.apache.neethi', module: 'neethi'
exclude group: 'org.codehaus.woodstox'
}
runtime ('org.apache.axis2:axis2-transport-local:1.5.1'){
exclude group: 'org.codehaus.woodstox', module: 'wstx-asl'
}
the conflict was gone.
I would like to confirm with 'dotmindlabs' on the issue with Axis2. I also used a few packages from Axis2 whilst implementing Apache CXF 3.2.1. I had the same problem "Cannot create a secure XMLInputFactory"
The issue was strictly to do with the additional libraries Axis2 Implements.
I have provided below the dependency (Maven) changes required to resolve this issue.
<!-- https://mvnrepository.com/artifact/org.apache.axis2/axis2-transport-http -->
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-transport-http</artifactId>
<version>1.6.2</version>
<exclusions>
<exclusion>
<groupId>org.apache.ws.commons.schema</groupId>
<artifactId>XmlSchema</artifactId>
</exclusion>
<exclusion>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.neethi</groupId>
<artifactId>neethi</artifactId>
</exclusion>
<exclusion>
<groupId>org.codehaus.woodstox</groupId>
<artifactId>wstx-asl</artifactId>
</exclusion>
</exclusions>
</dependency>
I hope this helps people in the future who run into this problem.

Dependency Convergence error for powermock

I want to use the last version of the powermock library (1.6.5) through Maven. But My package cannot be compiled, since Maven finds dependency Convergence error. Below you can see that there are 2 different versions of org.objenesis:objenesis library in the same dependency:
Dependency convergence error for org.objenesis:objenesis:2.1 paths to
dependency are:
+-mypackage:v1-SNAPSHOT
+-org.powermock:powermock-api-mockito:1.6.5
+-org.mockito:mockito-core:1.10.19
+-org.objenesis:objenesis:2.1
and
+-mypackage:v1-SNAPSHOT
+-org.powermock:powermock-api-mockito:1.6.5
+-org.powermock:powermock-api-mockito-common:1.6.5
+-org.powermock:powermock-api-support:1.6.5
+-org.powermock:powermock-reflect:1.6.5
+-org.objenesis:objenesis:2.2
I tried to make an exclusion, but I cannot exclude only one version, I need to exclude all of them, which does not pass me, as I think.
Did you have the same problem? What can I do?
There two different version of objenesis, because two different libraries depends on two different version ofobjenesis`: PowerMock and Mockito. You have two options to resolve the issue:
Exclude org.objenesis:objenesis from PowerMock dependencies and add it manually to your pom.
Exclude mockito-core from PowerMock dependencies and add it as separated decency to your pom with excluding objenesis.
I followed the answer from Arthur, but only made an exclusion for objenesis to the powermock-module-junit dependency. After that the enforcer plugins was happy.
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>1.7.0</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.objenesis</groupId>
<artifactId>objenesis</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito2</artifactId>
<version>1.7.0</version>
<scope>test</scope>
</dependency>

Neo4j 2.1.3 missing neo4j-kernal test-jar

I just tried upgrading to 2.1.3 and found the the following test-jar is missing from Maven Central:
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j-kernel</artifactId>
<version>2.1.3</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
I am looking to use the TestGraphDatabaseFactory, any chance it moved?
It is there, see http://repo1.maven.org/maven2/org/neo4j/neo4j-kernel/2.1.3/ having a neo4j-kernel-2.1.3-tests.jar.
I've just verified that the equivalent dependency in gradle just works fine:
testCompile group: 'org.neo4j', name: 'neo4j-kernel', version: '2.1.3', classifier: 'tests'
Maybe you're using Maven central behind a proxy that has not yet been updated?

java.lang.NoSuchFieldError: reportUnusedDeclaredThrownExceptionIncludeDocCommentReference

I got Exception
java.lang.NoSuchFieldError: reportUnusedDeclaredThrownExceptionIncludeDocCommentReference outside eclipse in command line using maven.
The gwt libraries are declared at the top of list of dependencies and GWT 2.5.1 is being used.
How to solve this issue? Please help
Well, I figured out what is the problem.
In my pom.xml , I have this dependency
<dependency>
<groupId>net.sf.jasperreports</groupId>
<artifactId>jasperreports</artifactId>
<version>4.7.0</version>
The problem with this is that, jasper reports has a dependency on jdtcore
<dependency>
<artifactId>jdtcore</artifactId>
<groupId>eclipse</groupId>
<version>3.1.0</version>
</dependency>
jdtcore actually creates a conflict with the gwt compiler. To solve this problem, I need to add an exclusion in the jasper dependency like this
<dependency>
<groupId>net.sf.jasperreports</groupId>
<artifactId>jasperreports</artifactId>
<version>4.7.0</version>
<exclusions>
<exclusion>
<artifactId>jdtcore</artifactId>
<groupId>eclipse</groupId>
</exclusion>
</exclusions>
</dependency>
Now if still need the jdtcore library in the web app (normally to dynamically compile jasper reports) we can add the dependency with scope runtime like this
<dependency>
<artifactId>jdtcore</artifactId>
<groupId>eclipse</groupId>
<version>3.1.0</version>
<scope>runtime</scope>
</dependency>
Last note, if anybody gets the problem, then should look if any dependency in pom.xml has got a dependency on jdtcore, exclude it and include it as runtime
Hope this helps
For gradle exclude transitive dependency as follows in build.gradle:
dependencies {
compile('net.sf.jasperreports:jasperreports:3.7.4') {
//Exclude as it caused problems with GWT:
//http://stackoverflow.com/questions/17991063/java-lang-nosuchfielderror-reportunuseddeclaredthrownexceptionincludedoccomment
exclude group: 'eclipse', module: 'jdtcore'
}
}
Except after I made this change my jasper compilation fails. I am not sure yet how can I get Jasper compilation and GWT compilation to coexist in same project?

Categories