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条回答
仙女界的扛把子
2楼-- · 2019-01-21 22:11

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.

查看更多
太酷不给撩
3楼-- · 2019-01-21 22:12

I had the same problem. I've changed maven version from 3.0.5 to 3.0.4 in Idea settings and all works fine now. Don't know why that helps me.

查看更多
我想做一个坏孩纸
4楼-- · 2019-01-21 22:13

This simple procedure takes about 1 minute without any risc.

  • Close IntelliJ
  • Delete ONLY the IntelliJ specific files like .idea/*, *.iml, .settings, etc. Suggested was deleting the POM as well, but that is not necessary IMHO.
  • Then re-create the project in IntelliJ using: File > New > Project from existing Sources > follow the steps. Be aware NOT to import multiple profiles or (same projects).
查看更多
祖国的老花朵
5楼-- · 2019-01-21 22:15

"symbol cannot be found" means that intellij is not able to resolve the "dependency". So, you can force "Dependency analysis" by clicking "Analyze" -> "Analyze Dependencies" then select the "Analysis Scope"

查看更多
孤傲高冷的网名
6楼-- · 2019-01-21 22:15

I closed the project and imported it again by clicking on the root pom (not just the folder, but the pom file itself).

查看更多
叼着烟拽天下
7楼-- · 2019-01-21 22:19

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

查看更多
登录 后发表回答