简体   繁体   English

在编辑器中显示 IntelliJ-idea 中的编译错误

[英]Showing compile error in IntelliJ-idea in editor

Showing compile error in IntelliJ-idea editor.在 IntelliJ-idea 编辑器中显示编译错误。

mvn clean install 

When run it will build successfully and run code normally.运行时它将成功构建并正常运行代码。 But in editor its unable to resolve those import.但是在编辑器中它无法解决这些导入。 Some of the import is showing correctly some of the import it's showing error like Blow某些导入正确显示某些导入显示错误,例如 Blow 在此处输入图像描述

and actually, the dependency is present in maven dependency list实际上,依赖项存在于 maven 依赖项列表中

在此处输入图像描述

In the editor, it showing full of error在编辑器中,它显示充满错误

I modified build settings, deleted repo, updated maven to the latest version, updated the IntelliJ and tried other suggestion in StackOverflow, still no solution for this problem.我修改了构建设置,删除了 repo,将 maven 更新到最新版本,更新了 IntelliJ 并尝试了 StackOverflow 中的其他建议,但仍然没有解决这个问题。

Try:尝试:

  • file > invalidate caches / restart file > invalidate caches / restart
  • maven tool window -> re-import / refresh: maven 工具窗口 -> 重新导入/刷新: Maven 工具窗口
  • check maven settings of IntelliJ: does it point to the same settings.xml and repository as the maven from the command line?检查 IntelliJ 的 Maven 设置:它是否指向与命令行中的 Maven 相同的 settings.xml 和存储库? IntelliJ is shipped with it's internal maven and might use different settings / repo than your plain maven from the command line. IntelliJ 随其内部 maven 一起提供,并且可能会使用与命令行中的普通 maven 不同的设置/存储库。

I believe this issue is related to the way we open this project in IntelliJ Idea as mvn clean install is working fine for you.我相信这个问题与我们在 IntelliJ Idea 中打开这个项目的方式有关,因为mvn clean install对你来说很好用。

While opening the project in IntelliJ, you should open maven project like this:在 IntelliJ 中打开项目时,您应该像这样打开Maven项目:

  • New -> Project from Existing Sources -> Select Project -> Import from External Model (Select maven here) New -> Project from Existing Sources -> Select Project -> Import from External Model(这里选择maven 在此处输入图片说明
  • After this, if you are asked to override .iml (idea files), you can override them.在此之后,如果您被要求覆盖 .iml(想法文件),您可以覆盖它们。 在此处输入图片说明

This should hopefully solve your problem.这应该有望解决您的问题。

You can invalidate the cache您可以使缓存无效

file -> invalidate caches and restart 

selecting first two options shown in invalidate cache has worked for, also you might get compile time error in already opened file so, try closing/opening these already opened files which are showing errors.选择无效缓存中显示的前两个选项已起作用,您也可能在已打开的文件中遇到编译时错误,因此,请尝试关闭/打开这些显示错误的已打开文件。

  1. Clear file system cache and Local History : remove the virtual file system cache together with the information stored in Local History.清除文件系统缓存和本地历史记录:删除虚拟文件系统缓存以及存储在本地历史记录中的信息。

     This action might be helpful for troubleshooting purposes when the usual cache invalidation is not enough to solve the problem.
    1. Ask before downloading new shared indexes : show a notification prompting you to download new shared indexes as they become available.在下载新的共享索引之前询问:显示一条通知,提示您下载可用的新共享索引。
     Enabling this option also updates your settings for shared project indexes in Settings/ Preferences | Tools | Shared Indexes.
    1. Clear downloaded shared indexes : remove the downloaded shared index files.清除下载的共享索引:删除下载的共享索引文件。

If it helps, I also had to bump up the heap size for compiler to get past this issue.如果有帮助,我还必须增加编译器的堆大小才能解决这个问题。

在此处输入图片说明

尝试删除项目下的 .idea 文件夹,完全关闭项目并重新导入,它对我有用。

I resolved this issue by deleting the local maven repository and restoring the default setting of Intellij我通过删除本地maven存储库来解决此问题,并还原Intellij的默认设置

  1. Go to File --> Manage IDE Settings --> Restore Default Settings Z5F075AE3E3E1F9D0382BB8C4632991F96FZ file->管理Z581D6381D6381F35E4F9D77201ACF87B364Z
  2. Go to File --> Settings --> Build, Execution, Deployment --> Build Tools --> Maven --> Get the Local repository path and delete it. Z5F075AE3E1F9D0382BBBB8C4632991F96FZ file->>设置 - > build,build,execution,exployment-> build tools-> Z9115C1098064131313F2444AC1A377F7Z->获取本地repososito and deleTe and itelete it it it ite it it it ite it it it it ite it it it ite it it it it it ite it it it it it ite it it it it ite it it it it it it it it it it it it it it ite f。
  3. Open Intellij --> open project --> Go to Terminal --> mvn clean install --> error will disappear after build success Open Intellij-> Open Project-> Z5F075AE3E3E1F9D0382BB8C4632991F96FZ到终端 - > MVN CLEAN INSTALS->构建成功后错误将消失

Go to project and do reimport. Go 进行投影并重新导入。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM