Reputation: 20581
Yesterday I refactored my project and I changed layout of my packages (I moved some packages into another packages, created new packages etc). But now, when I try to run JUnit test I get NoSuchMethodError
on methods which name is changed after refactoring. Also, when I change other code in methods, IDEA still running old code.. I tried to run "Invalidate caches" in File menu, also I tried to reboot computer - no result. Where can be problem?
EDIT: Yesterday after moving packages IDEA doesn't correctly change package declarations in .java
files, so I changed them by hand
Upvotes: 21
Views: 40560
Reputation: 1
Try the following solution:
Upvotes: 0
Reputation: 351
I had this issue running with WSL2. I know I have problems with my environment but the way I got this to work was to add a build step to run a maven goal of clean before the build.
Configuration: Edit
Choose your configuration to edit
Modify Options
Before Launch
Add Before Launch Task
Run Maven Goal
In the command Line field enter in "clean"
I have to rebuild everything, but it works. If you are running tests, you most likely need to update your test template, so it works every time when you choose to run a subset of test. You most likely will need to delete all the existing build configurations for your unit test so it will take in the new test template.
In the same Run/Debug Configurations Windowchoose the Edit Configuration Templates
Choose your test framework. Mine is JUnit, Then follow the same steps as above
Upvotes: 1
Reputation: 402
Found this posting from IntelliJ and Maven not finding POM changes. Had to Reload All Maven projects to fix it. Maven panel, upper left corner circle of arrows button.
Upvotes: 0
Reputation: 2248
What I did in order to solve the issue was to "invalidate and Restart":
File -> invalidate and Restart
Upvotes: 7
Reputation: 69
This worked for me.
In IntelliJ IDEA,
Then you can navigate to Local Changes Tab.
Upvotes: -1
Reputation: 1
Try deleting .class file of class where nosuchmethod error is throwing, and recompile.
Upvotes: 0
Reputation: 81
Answer to an old question, but:
If you're using a Run Configuration, make sure in the "Before Launch" section of the "Run/Debug Configurations" dialog, you have added "Build". It seems to get removed from this dialog sometimes, even if you have it added in the default settings.
Upvotes: 4
Reputation: 1194
Another root-cause can be:
If you are using Lombok, try to deinstall/reinstall the Intellij Lombok Plugin.
That solved such a strange behaviour in my case!
Upvotes: 0
Reputation: 2794
VCS -> Refresh File Status solved this for me, when Intellij suddenly stopped noticing changes.
Upvotes: 8
Reputation: 20581
SOLUTION:
Error magically gone after 2 things:
I imported this project into eclipse and run JUNit test from eclipse. Then I returned to IDEA and deleted all Eclipse specific files.
I synchronized my project (File->Synchronize).
I don't know what actually was the solution of problem, but for suggestions I accept @SeanLandsman's answer
Upvotes: 4
Reputation: 7179
I have two suggestions you could try here
With regards to your edit - I've not seen this myself. Whenever I've renamed or moved files (including packages) these changes have been correctly applied to all applicable files. Are you refactoring with Refactor>Move / Refactor->Copy ?
Upvotes: 3