Maven builds are working, but junit is throwing a NoSuchMethodError
So I'm using Raptor (I believe that's an in house version of Eclipse) which forces certain dependency version installs (even without a pom). Even though I only had the right versions in my pom files, Raptor was installing incompatible versions before hand, which took precedence. (at least thats what I believe was happening)
I had to do some forceful version control in my parent pom using dependency managers, and I seemed to have cleared up the issue. Though a few more problems followed with the libraries not having the correct methods. I ended up resolving those issues by finding versions of the dependencies (allowed by companies repository manager) that worked together (a lot of tinkering and seeing which versions would play nice). Because of the repository manager I was unable to download just the latest version of each dependency I needed.
If you are experiencing this problem make sure your versions are compatible, if you can get the newest version of the dependencies do that. If not, grab a beer, and start with the latest versions offered by your repository manager and start trying to find versions that work with each other.
How do I fix a NoSuchMethodError?
Without any more information it is difficult to pinpoint the problem, but the root cause is that you most likely have compiled a class against a different version of the class that is missing a method, than the one you are using when running it.
Look at the stack trace ... If the exception appears when calling a method on an object in a library, you are most likely using separate versions of the library when compiling and running. Make sure you have the right version both places.
If the exception appears when calling a method on objects instantiated by classes you made, then your build process seems to be faulty. Make sure the class files that you are actually running are updated when you compile.
AspectJ + Junit + Maven - pointcut recognized in tests but NoSuchMethodError: aspectOf() exception thrown
So, the trick was to compile that library with my aspects not with javac but with ajc
(aka aspectj-maven-plugin)
That's it. I just had to add this into the maven module with aspects (they are in src/main/java)
Aspects are annotation ridden so you have to have 1.6 source/target/compliance level
ASPECTJ MODULE
<!-- Build -->
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.4</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<complianceLevel>1.6</complianceLevel>
<verbose>true</verbose>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
<dependencies>
</dependencies>
</plugin>
</plugins>
</build>
Than you have to add this module as a test dependency into your target module you want to use aspects with
TARGET MODULE
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.4</version>
<configuration>
<aspectLibraries>
<aspectLibrary>
<groupId>that-artifact</groupId>
<artifactId>mentioned-above</artifactId>
</aspectLibrary>
</aspectLibraries>
<source>1.6</source>
<target>1.6</target>
<complianceLevel>1.6</complianceLevel>
</configuration>
<executions>
<execution>
<goals>
<goal>test-compile</goal>
</goals>
<configuration>
<showWeaveInfo>true</showWeaveInfo>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
You have to use 1.6 level everywhere
NoSuchMethodError with Hamcrest 1.3 & JUnit 4.11
This blog helped fix the same problem for me:
https://tedvinke.wordpress.com/2013/12/17/mixing-junit-hamcrest-and-mockito-explaining-nosuchmethoderror/
Inside the dependencies for Mockito and Junit, the author added excludes:
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<exclusions>
<exclusion>
<artifactId>hamcrest-core</artifactId>
<groupId>org.hamcrest</groupId>
</exclusion>
</exclusions>
</dependency>
Why does JUnit 4.12 throw a NoSuchMethodError for assertEquals when using @RunWith(SpringJUnit4ClassRunner.class)?
You have two JARs on your classpath providing the same class : org.junit.Assert
.
One of them is the one you expect : the one from junit:junit
, the other one (and it is the one being picked by the classloader) is from org.glassfish.distributions:web-all
.
As a solution you might want to pick the latest version of web-all which does not include anymore the org.junit bunch of classes.
This is the kind of situation where the duplicate-finder Maven plugin would have helped.
Related Topics
Shifting Characters Within a String
How to Print Even and Odd Position Characters of an Array of Strings in Java
Junit 5 - No Parameterresolver Registered for Parameter
Getting Column Names from a JPA Native Query
Base64: Java.Lang.Illegalargumentexception: Illegal Character
Java - How to Find Students With Their Highest Marks Writing a Method in a Student Class
Can We Use Multipart and @Requestbody Together in Spring
Remove Quote from the Jsonarray Output
Bootstrap.Yml Not Loading in Spring Boot 2
How to Check If a Date Is After Today Java
How to Use If-Else Logic in Java 8 Stream Foreach
How to Send List of Long to Rest Controller Spring Boot
Set Zoom Level to 100% in Selenium Webdriver When Default Is Not 100
Spring JPA Selecting Specific Columns
Java 8: How to Write Lambda Stream to Work With Jsonarray
Get Current Week Start and End Date in Java - (Monday to Sunday)
How to Make Sonar Ignore Some Classes for Codecoverage Metric
Selenium Webdriver: Clicking on Elements Within an Svg Using Xpath