Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Command line mvn compile, but not IntelliJ

I am having trouble compiling a Maven project in IntelliJ.

  • If I run mvn clean install from commandline = SUCCESS
  • If I click on the "Reimport All Maven Projects" icon in IntellJ = SUCCESS
  • If I click on the "Generate Sources and Update Folders For All Projects" icon in IntelliJ = SUCCESS
  • If I click on the "install" Lifecyclein the Maven Projects panel = SUCCESS
  • After the Maven "install" I can even run the application without problems and I can see my latest source code changes.

Therefore I don't believe there is anything wrong with the project itself. But

  • IntelliJ shows there are a lots of methods and fields missing (red highlights)
  • Make Module ... fails
  • Compile Module ... fails
  • All Unit Tests running from IntelliJ fail with "java: cannot find symbol" errors, but PASS from the command line

I have

  • restarted the IDE several times
  • Click File -> Invalidate Caches/Restart...
  • Click File -> Project Structure... -> Problems = Empty panel (I assume it means no problems)
  • Click File -> Settings... -> Maven = Maven settings is correct

What else could I try to make IntelliJ intelligent enough to compile the project?

like image 603
Jasper Citi Avatar asked Jun 28 '17 08:06

Jasper Citi


2 Answers

This can happen if command line uses a different version of mvn than IntelliJ. Make sure that Intellij is using the same maven executable that command line is using. First type: "which mvn" to find out the mvn executable that command line is using. Then make IntelliJ use the same version by going to: Intellij => Preferences => Build, Execution and Deployment => Build Tools => Maven => Maven Home Directory. Mvn Settings in IntelliJ 2017.1

like image 34
ssiddiqu Avatar answered Sep 29 '22 20:09

ssiddiqu


I faced similar problem. Solution is, set the IntelliJ maven home directory to the installed maven location. Goto File->Settings And then set the maven home directory as shown in the image:

enter image description here

like image 137
Junaed Avatar answered Sep 29 '22 19:09

Junaed