Maven package works but Intellij's build fails

2019-01-21 21:25发布

I have a JDK 1.7 project with a maven dependency to a local jar in my maven repo.

I'm unable to build the project using Intellij, with the errors that a symbol cannot be found (the symbol is a class importing packages from the local jar)

But I can successfully build the project using 'mvn package'.

I've spent so much time looking for solutions, things I've already done:

  • Invalidated cache
  • 'mvn clean install' the local jar dependecy
  • Marked to 'autoload snapshots' in Intellij's maven configuration
  • Reimpoted maven in Intellij
  • Syncornized

This error happend to my couple of times before, but usually just closing the Intellij and /or doing the 'mvn clean install' did the trick.

Please help.

16条回答
smile是对你的礼貌
2楼-- · 2019-01-21 22:06

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

查看更多
SAY GOODBYE
3楼-- · 2019-01-21 22:06

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

查看更多
We Are One
4楼-- · 2019-01-21 22:07

Many valuable tips in the other answers here, just want to add the solution that worked for my problem.

We recently started using a private Maven repository and always do mvn -s settings.xml when invoking the Maven cmdline. IntelliJ does of course not know about the private repo, so it needs a little help.

Go to Settings -> Build, Execution, Deployment -> Build tools -> Maven and override the "User Settings file" option.

enter image description here

查看更多
The star\"
5楼-- · 2019-01-21 22:09

I tried invalidating cache, changing the Maven to installed version and nothing worked.

Closing and recreating a new project resolved it.

查看更多
6楼-- · 2019-01-21 22:10

Maven ReImport worked for me like below...

enter image description here

查看更多
走好不送
7楼-- · 2019-01-21 22:10

In my case my iml was not in sync, so I deleted the iml for the specific module and then under maven option select unignore project to recreate iml

查看更多
登录 后发表回答