IntelliJ community edition compiles a maven project despite compilation errors, why?


I spend someitme today trying to figure out what is wrong with my code and come across the fact that the maven project was compiling despite have compilation issues (red in editor). I am not sure which settings I changed to cause this but I am sure that I dont have the eclipse compiler installed in my computer (I know that compiler can do this).

Any idea what can be wrong?


Comment actions Permalink

Is it a multi-module project? If so, is the error in the module you are compiling? If you compile a single module, maven (and therefore IDEA) uses the version of the module in your local maven repository and not the code in the editor. When you compile multi modules, from a parent pom for example, maven creates all the artifacts, and then uses the built artifact to satisfy any multi-module inter-dependencies.

If that is not it, what happens from the command line when you run the maven build?

Comment actions Permalink

It is a single module and the errors are in the module's source code. So when I right click and select the run button on the maven project view it compiles fine (while it has 10 red lines in the code) but the same project fails to compile from the command line when I use "mvn clean install" for it.
Note that I use the same maven for intellij that I have installed in my system (changed the maven path and settins int he IntelliJ settings so that it use my global settings). The errors that it fails to catch and ignores when compiling are constructor parameters related, e.g e.g I refactored the constructor to have 6 parameters and in one of the classes that I was using that class's constructor I forgot to add the other parameter when creating the objects. This is a compilation error when I compile in command line and is ignored when I compile inside intelliJ.

Comment actions Permalink

sarahk wrote:
I am sure that I dont have the eclipse compiler installed in my computer (I know that compiler can do this)

Just as an aside FYI, IntelliJ IDEA comes with the eclipse compiler bundled in it. It can be set as the compiler to use in Settings > Compiler > Java Compiler > Use Compiler, But I do not think that is your issue since that is the compiler used when IntelliJ IDEA compiles the project directly. If you use maven within IntelliJ IDEA, it uses the JDK defined in the Maven > Runner settings. This usually defaults to the Project JDK.

So if I understand you correctly, a maven build succeeds when the maven build is launched from within IDEA, but fails (as it should) when run from the command line. Hmm... Nothing jumps to mind that would cause this behavior.

If I understand how a maven build runs withing IntelliJ IDEA, it does not directly call the mvn script. It calls it's own Java application that launches maven in a similar way that the mvn script does. But there is the possibility for an inconsistency to occur. If you look at the command line output when you run a maven build within IntelliJ IDEA, you will see it calls 'java', not 'mvn'. Java runs 'com.intellij.rt.execution.application.AppMain' to which are passed various arguments. It would seem that something in that arrangement is going wrong for you.

Here are some things I can suggest to try and troubleshoot and maybe resolve the issue:

  • Force re-import the maven project within IntelliJ IDEA (via the reimport button on the maven tool window). Do it two ro three times in a row.
  • When you run the maven build within IDEA, take a look at the command line it is using (shown at the top of the console window) See if there is anything strange in there (a misconfiguration of some type). Keep in mind it uses a different application than the mvn script to launch.
  • Change the "Output Level" to debug in the Maven Runner settings in IDEA. Look through the detailed output. Make sure it is compiling the correct file path.
  • You can try invalidating IDEA's caches (File > Invalidate cache). I can;t see how that would be affecting things, but it might be worth a try.
  • While I generally hate "nuke it and start over" solutions, it might be worth just creating a new IDEA project and see if the same behavior occurs.

I hope this helps. I wish I could give a more definitive answer. Perhaps someone else can.


Please sign in to leave a comment.