Reputation: 1872
I am having trouble compiling a Maven project in IntelliJ.
mvn clean install
from commandline = SUCCESSTherefore I don't believe there is anything wrong with the project itself. But
I have
What else could I try to make IntelliJ intelligent enough to compile the project?
Upvotes: 16
Views: 20849
Reputation: 4759
I had lot of issues around this very obvious looking problem.
In summary the problem was
pom.xml defining <java.version>21</java.version>
And I was using IntelliJ Idea 2021 version.
On this version of IntelliJ problem was solved by using Bundled Maven 3
in Settings -> Build, Execution , Development -> Maven -> Maven Home Path -> Bundled Maven 3
However later I was facing other problems related to usage of Java 21 like release version 21 not supported
and java: No enum constant javax.lang.model.element.Modifier.SEALED
and eventually had to use latest IntelliJ IDE 2024.2.4 and that solved the problem.
Upvotes: 0
Reputation: 1
Have been facing this issue for long now, and usually the root cause for it is different maven version running on IntelliJ as mentioned above, but also sometimes it can be caused by different version of Java selected in the project structure.
As for me even after aligning the maven version the issue would not go, but once I checked the java version, Intellij had by defaulted selected Java 11 for me, and once I changed it back to Java 8, it started working again.
Upvotes: 0
Reputation: 1937
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:
Upvotes: 1
Reputation: 31
I encountered a similar issues with compiling to Java 11 from IntelliJ Maven compile indicating that com.sun.management.HotSpotDiagnosticMXBean#dumpHeap()
did not exist.
After trying the above steps, I still could not get it to resolve. I had recently migrated to a new instance of Ubuntu and decided to fire up my old VM, where the code compiled without an issue. So it occurred to me that when I installed IntelliJ on the new VM, I chose to download AdoptOpenJDK 11 (adopt-openj9-11.0.7) via IntelliJ SDK download feature.
So I manually downloaded and installed a fresh copy of OpenJDK 11 (jdk-11.0.6+10), then changed the project's default SDK to the new one I installed, and everything compiled just fine.
I hope this answer may help others.
Upvotes: 0
Reputation: 1872
After a few years, I came across the same issue again but with another project. In this case IntelliJ was missing the Lombok plugin which generates the missing sources.
To install:
Upvotes: 1
Reputation: 637
Just ran into this problem. What worked for me was to close the project and delete the .idea folder.
Reopened the project then set it up as a maven project again...
All good after that.
Upvotes: 7
Reputation: 5155
Check the JDK setting for the project. In my experience, that is the most common cause of bizzare Intellij-cannot-compile problems.
Under "Project Settings" (CMD-,) - see the "Project SDK" setting.
Make sure it's a valid SDK, and the version matches the required version for the sources (i.e. check the maven compiler plugin source/target settings, and make sure the selected SDK is at least that version, or higher).
Upvotes: 2
Reputation: 121
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
Upvotes: 12
Reputation: 1
I've had this issue when I've had generated sources. Maven wasn't setup to mark the compiled-test-sources folder as a test sources root, so every time I did something with Maven I had to mark the generated folders.
Upvotes: 0