Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven package works but Intellij's build fails

People also ask

Why does Maven build failure in eclipse?

The error message indicates that Maven is unable to find the Java compiler, which comes only with a JDK and not with a JRE.

How do I build a project using mvn clean package?

Let's open the command console, go the C:\MVN\consumerBanking directory and execute the following mvn command. Maven will start building the project. We give maven two goals, first to clean the target directory (clean) and then package the project build output as jar (package).

How do I force Maven to download dependencies IntelliJ?

Press Ctrl + Shift + A to find actions, and input "reload", you will find the "Reload All Maven Projects". On a Mac, use ⌘ + ⇧ + A instead. @Winnemucca I just did it on 2017.2. Waiting for it to finish now.


I know this is late but executing mvn idea:idea solves the issue.

The command re-generates the crucial IntelliJ IDEA files: ipr, iml, and iws, and thus re-align them with your pom.xml.

Documentation: https://maven.apache.org/plugins/maven-idea-plugin

The plugin is retired but still (as of 05.06.2021) works like magic :)


Try to delete all .iml and your POM. Then copy and paste your POM again to your project and re-open and re-import it.


Maven ReImport worked for me like below...

enter image description here


Adding some more tips since this is the first thing that came up in the search when I was having similar problems (project builds in mvn, not in IntelliJ), in case it might help someone else.

When I had this it was a different fix on Windows and Mac.

On Mac, I went into ItellijIDEA / Preferences / Build, Execution, Deployment / Build Tools / Maven / Maven Home Directory and set it to use my separately installed Maven rather than the bundled Maven. All the build problems went away.

On Windows, I was seeing exceptions in the idea.log related to SSL and my project tree had only Java under the External Libraries branch. From looking at other sites it sounds like IntelliJ uses its own private JDK instead of the system one (even though in my case I already had the exact same JDK version installed). My system JDK has certs installed in the keystore for the corporate Nexus server that the IntelliJ private JDK didn't have, so exceptions were being thrown when it tried to get files from Nexus. For this the solution was to quit IntelliJ, set an environment variable called IDEA_JDK to point to the JDK I already had installed that had the proper certs and restart IntelliJ. All the build problems went away.


I've found out that my .iml file and pom were conflicting and causing the issue.


IDE uses its own bundled copy of Maven when doing builds. If maven on terminal is different from IDE, then you want them to be the same.

GOTO (On a Mac)- IntelliJ Idea -> Preferences -> Build,Execution,Deployment -> Build Tools -> Maven. Set the path for your Maven Home Directory To find the path for Maven which you use from terminal, type command mvn -version and that should print out bunch of details including the dir path. Put that in Maven Home Directory.

To be safe you can also do the same for JDK location

==== Some Other Things that can cause such issues ===

If doing mvn package or mvn clean install builds, then it has to do something with IDE caches. Among other things, this one usually helps with such errors -->

File -> Invalidate Caches


I know I am pretty late to this conversation, but just wanted to post this in case someone else comes across this problem. Another reason why this happens is because you are not referring to the right repository. Intellij picks up the bundled version of a jar by default instead of the one from your own maven repository. Confirm that the repository connected is the right one.