WelcomeTo
WelcomeTo

Reputation: 20581

Intellij IDEA doesn't detect changes

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

Answers (12)

Ionut
Ionut

Reputation: 1

Try the following solution:

  • Go to Run/Debug Configuration
  • Click on "Modify options"
  • Tick the "Add before launch task" option
  • Add "Build Project" as new task

Upvotes: 0

McFrank
McFrank

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

enter image description here

Choose your test framework. Mine is JUnit, Then follow the same steps as above

Upvotes: 1

Richard Keene
Richard Keene

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

Eyal Sooliman
Eyal Sooliman

Reputation: 2248

What I did in order to solve the issue was to "invalidate and Restart":

enter image description here

File -> invalidate and Restart

Upvotes: 7

Viveksuriyan
Viveksuriyan

Reputation: 69

This worked for me.

In IntelliJ IDEA,

  1. Right click on the project.
  2. Select Git -> Show History.
  3. Opens "Version Control"

Then you can navigate to Local Changes Tab.

Upvotes: -1

Arunraj Nair
Arunraj Nair

Reputation: 145

Deleting the entire content of the classes dir worked for me

Upvotes: 1

sahanashivu
sahanashivu

Reputation: 1

Try deleting .class file of class where nosuchmethod error is throwing, and recompile.

Upvotes: 0

CJDownUnder
CJDownUnder

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

Dirk
Dirk

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

Stoffe
Stoffe

Reputation: 2794

VCS -> Refresh File Status solved this for me, when Intellij suddenly stopped noticing changes.

Upvotes: 8

WelcomeTo
WelcomeTo

Reputation: 20581

SOLUTION:

Error magically gone after 2 things:

  1. I imported this project into eclipse and run JUNit test from eclipse. Then I returned to IDEA and deleted all Eclipse specific files.

  2. 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

Sean Landsman
Sean Landsman

Reputation: 7179

I have two suggestions you could try here

  • Edit your test configuration(s) and ensure that they're pointing to what you expect them to. I've sometimes seen a refactoring not being picked up in the run configuration and I've had to manually change it
  • Less likely to work, but try to synchronize your project: File->Synchronize. Do this at the highest level of your project

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

Related Questions