可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
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.
回答1:
I know this is late but executing mvn idea:idea
solves the issue.
回答2:
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.
回答3:
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.
回答4:
I've found out that my .iml file and pom were conflicting and causing the issue.
回答5:
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.
回答6:
Maven ReImport worked for me like below...
回答7:
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
回答8:
"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"
回答9:
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
回答10:
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.
回答11:
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.
回答12:
I tried invalidating cache, changing the Maven to installed version and nothing worked.
Closing and recreating a new project resolved it.
回答13:
I closed the project and imported it again by clicking on the root pom (not just the folder, but the pom file itself).
回答14:
I tried everything above with no joy. However I did one thing that finally got it to work:
I went to C:\Users\.IntellijJIdea2018.2 and just deleted the entire folder.
It removes all the settings and cache for IntelliJ. I had to reimport my project from scratch but a simple remove and reimport hadn't worked before, but this finally got it working again.
回答15:
If you are using gradle , try below command.This resolved my issue
gradle cleanIdea idea
回答16:
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).