Java Maven 包有效,但 Intellij 的构建失败
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18316857/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Maven package works but Intellij's build fails
提问by Yarin Miran
I have a JDK 1.7 project with a maven dependency to a local jar in my maven repo.
我有一个 JDK 1.7 项目,它对我的 Maven 存储库中的本地 jar 有 Maven 依赖。
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)
我无法使用 Intellij 构建项目,错误是找不到符号(符号是从本地 jar 导入包的类)
But I can successfully build the project using 'mvn package'.
但是我可以使用“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
- 无效的缓存
- 'mvn clean install' 本地 jar 依赖
- 在 Intellij 的 Maven 配置中标记为“自动加载快照”
- 在 Intellij 中重新导入 maven
- 同步的
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.
这个错误发生在我之前几次,但通常只是关闭 Intellij 和/或执行 'mvn clean install' 就可以了。
Please help.
请帮忙。
采纳答案by Yarin Miran
I've found out that my .iml file and pom were conflicting and causing the issue.
我发现我的 .iml 文件和 pom 存在冲突并导致了这个问题。
回答by dgm
"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"
“找不到符号”意味着 Intellij 无法解决“依赖关系”。因此,您可以通过单击“分析”->“分析依赖关系”然后选择“分析范围”来强制进行“依赖关系分析”
回答by masoodg
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.
尝试删除所有 .iml 和您的 POM。然后再次将您的 POM 复制并粘贴到您的项目中,然后重新打开并重新导入它。
回答by Boris Mitioglov
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.
我有同样的问题。我已经在 Idea 设置中将 Maven 版本从 3.0.5 更改为 3.0.4,现在一切正常。不知道为什么这对我有帮助。
回答by rrjp
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.
添加更多提示,因为这是我遇到类似问题时搜索中出现的第一件事(项目构建在 mvn 中,而不是在 IntelliJ 中),以防它可能对其他人有所帮助。
When I had this it was a different fix on Windows and Mac.
当我有这个时,它在 Windows 和 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.
在 Mac 上,我进入 ItellijIDEA / Preferences / Build, Execution, Deployment / Build Tools / Maven / Maven Home Directory 并将其设置为使用我单独安装的 Maven 而不是捆绑的 Maven。所有的构建问题都消失了。
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.
在 Windows 上,我在idea.log 中看到与 SSL 相关的异常,并且我的项目树在外部库分支下只有 Java。从查看其他站点,听起来 IntelliJ 使用自己的私有 JDK 而不是系统 JDK(即使在我的情况下我已经安装了完全相同的 JDK 版本)。我的系统 JDK 在企业 Nexus 服务器的密钥库中安装了 IntelliJ 私有 JDK 没有的证书,因此当它尝试从 Nexus 获取文件时会抛出异常。为此,解决方案是退出 IntelliJ,设置一个名为 IDEA_JDK 的环境变量指向我已经安装的具有正确证书的 JDK,然后重新启动 IntelliJ。所有的构建问题都消失了。
回答by Optimiser
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.
我知道我对这次谈话已经很晚了,但只是想发布这个以防其他人遇到这个问题。发生这种情况的另一个原因是您没有引用正确的存储库。默认情况下,Intellij 会选择 jar 的捆绑版本,而不是您自己的 maven 存储库中的那个。确认连接的存储库是正确的。
回答by Rahul Jha
I know this is late but executing mvn idea:idea
solves the issue.
我知道这已经晚了,但执行mvn idea:idea
解决了问题。
回答by ARK
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.
IDE 在进行构建时使用它自己的 Maven 捆绑副本。如果终端上的 maven 与 IDE 不同,那么您希望它们相同。
GOTO (On a Mac)-
IntelliJ Idea -> Preferences -> Build,Execution,Deployment -> Build Tools -> Maven. Set the path for your Maven Home DirectoryTo 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.
转到(在 Mac 上)- IntelliJ Idea -> 首选项 -> 构建、执行、部署 -> 构建工具 -> Maven。设置您的Maven 主目录的路径 要从终端中找到您使用的 Maven 的路径,请键入命令mvn -version
,它应该会打印出包括目录路径在内的一系列详细信息。把它放在Maven Home Directory 中。
To be safe you can also do the same for JDK location
为了安全起见,您也可以对 JDK 位置执行相同操作
==== 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 -->
如果执行 mvn package 或 mvn clean install 构建,那么它必须对 IDE 缓存做一些事情。除其他外,这通常有助于解决此类错误-->
File -> Invalidate Caches
文件 -> 无效缓存
回答by Johannes Rudolph
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.
我们最近开始使用私有 Maven 存储库,并且mvn -s settings.xml
在调用 Maven cmdline 时总是这样做。IntelliJ 当然不知道私有仓库,所以它需要一点帮助。
Go to Settings -> Build, Execution, Deployment -> Build tools -> Maven and override the "User Settings file" option.
转到设置 -> 构建、执行、部署 -> 构建工具 -> Maven 并覆盖“用户设置文件”选项。