Linux IDEA JetBrains IntelliJ - 'make' 上的编译错误,但使用 Maven 编译时很好,并且 IntelliJ 在类文件中没有报告错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3677174/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-03 23:22:31  来源:igfitidea点击:

IDEA JetBrains IntelliJ - Compile error on 'make' but fine when compiled using Maven and no errors reported by IntelliJ in the class file

javamaven-2intellij-ideacompilation

提问by Ed .

So I have a maven module (module-A) in IntelliJ. I recently moved some classes from it into another new maven module (module-B) and added a dependency to it. Once I had done this I also modified the signature of a method of one of the moved classes (now in module-B).

所以我在 IntelliJ 中有一个 Maven 模块(模块-A)。我最近将一些类从它移到另一个新的 maven 模块(模块-B)并添加了一个依赖项。完成此操作后,我还修改了其中一个移动类(现在在模块 B 中)的方法的签名。

I re-imported the poms so that IntelliJ would pick up the dependency changes and ensured all Java imports for the affected files were correct again. Now when I attempt to run my webapp (which depends on the two modules) I get a compile error in a class in module-A calling the modified method of the class in module-B.

我重新导入了 poms,以便 IntelliJ 能够获取依赖项更改并确保受影响文件的所有 Java 导入再次正确。现在,当我尝试运行我的 web 应用程序(这取决于两个模块)时,我在模块 A 中的类中调用模块 B 中类的修改方法时遇到编译错误。

The error message is basically saying that that method doesn't exist but believes the old method still exists! I click on the 'make' error and it takes me to the line in a class in module-A calling the modified method...the weird thing is, IntelliJ knows it is fine in the file. i.e. The method is not underlined in red like a compile error would normally be, but the class file name is :(

错误消息基本上是说该方法不存在但认为旧方法仍然存在!我点击'make'错误,它把我带到模块A中的一个类中的行调用修改后的方法......奇怪的是,IntelliJ知道它在文件中没问题。即该方法不像通常的编译错误那样用红色下划线标出,但类文件名是:(

I compiled it from the command line using 'mvn install' (having also installed module-B) and it is all successful. I have deleted the classes directory in the target of both module-A and module-B and also invalidated IntelliJ's caches and restarted...still happening...any ideas?

我使用'mvn install'(还安装了module-B)从命令行编译了它,一切都成功了。我已经删除了模块 A 和模块 B 的目标中的类目录,并使 IntelliJ 的缓存无效并重新启动......仍然发生......有任何想法吗?

采纳答案by Ed .

So just stated it up this morning and it's all working!

所以今天早上刚说出来,一切都奏效了!

Last night what I did do was open a new project (intelliJ project) from module-A's and module-B's parent pom and successfully got it to build, possibly doing that and then opening my original project again fixed it somehow...very annoying though

昨晚我所做的是从模块 A 和模块 B 的父 pom 打开一个新项目(intelliJ 项目)并成功构建它,可能这样做然后再次打开我的原始项目以某种方式修复它......非常烦人尽管

回答by Colin Hebert

Try to mvn cleanyour projects and mvn installyour project B.

尝试mvn clean你的项目和mvn install你的项目 B.

The maven integration with intelliJ is kind of buggy when you use the make command directly provided by Intellij. You should directly use the mvn commands, or start them from the maven panel.

当您使用 Intellij 直接提供的 make 命令时,maven 与 intelliJ 的集成有点问题。您应该直接使用 mvn 命令,或者从 maven 面板启动它们。

回答by user1239332

Change "Java Compiler" setting in IDEA (User compiler javac in-process) to fix the problem.

更改 IDEA 中的“Java Compiler”设置(User compiler javac in-process)以解决问题。

回答by bsautner

I spent a few hours on this same issue. All of the cleans in the world didn't help.

我在同样的问题上花了几个小时。世界上所有的清洁都无济于事。

I deleted my out and target directory in my project and recompiled - that cleared it.

我删除了项目中的 out 和 target 目录并重新编译 - 清除了它。

Edit: There is also a magic feature under the file menu: "Invalidate Caches / Restart" This fixes a bunch of "intellij is confused" problems.

编辑:文件菜单下还有一个神奇的功能:“无效缓存/重启”这修复了一堆“intellij被混淆”的问题。

回答by Ivan Voroshilin

Maven Projects -> Reimport should help.

Maven 项目 -> 重新导入应该会有所帮助。

回答by Fortytwo

I just had a similar issue that was driving me insane. I had done all the other things mentioned in the answers above because I have used Intellij forever, but none worked. In the end I found out that in the maven projects portion of Intellij, one of my modules had been marked "ignore" a simple unignore command from the context menu did the trick.

我刚刚遇到了一个让我发疯的类似问题。我已经完成了上面答案中提到的所有其他事情,因为我一直使用 Intellij,但都没有奏效。最后我发现在 Intellij 的 maven 项目部分,我的一个模块被标记为“忽略”,上下文菜单中的一个简单的 unignore 命令就成功了。

回答by spudfkc

I ran across a very similar problem that was driving me insane.

我遇到了一个非常相似的问题,这让我发疯。

My code would compile fine with the ant task I normally run, but it would not build in IntelliJ, complaining about "Cannot Find Symbol blah blah"

我的代码可以用我通常运行的 ant 任务编译得很好,但它不会在 IntelliJ 中构建,抱怨“找不到符号等等”

Turns out, you can add "Excluded" files for the compiler. My file somehow got added to that list.

事实证明,您可以为编译器添加“排除”文件。我的文件不知何故被添加到该列表中。

This list is located in File > Settings > Compiler > Excludes (IntelliJ 13)

此列表位于文件 > 设置 > 编译器 > 排除 (IntelliJ 13)

回答by Nodebody

I had a very similar behavior. Running (Scala-)tests would always fail due to errors in unrelated java classes during the 'make' step.

我有一个非常相似的行为。由于在“make”步骤中不相关的java类中的错误,运行(Scala-)测试总是会失败。

It turned out, I had included a 'global' SDK library that collided with one of the dependencies from the project. A proper helpful error message only showed up after I deleted the 'make' step from the test. I then deleted the duplicate library, re-added the make step to the test and everything is now working fine.

事实证明,我包含了一个“全局”SDK 库,该库与项目中的一个依赖项发生冲突。仅在我从测试中删除“制作”步骤后才会出现正确有用的错误消息。然后我删除了重复的库,将 make 步骤重新添加到测试中,现在一切正常。

回答by amigobot

I ran into this problem today after upgrading from 12 to 13.

我今天从 12 升级到 13 后遇到了这个问题。

Later I fixed issue as I used the same name for Project and Module and looks Intellij allows this but cannot handle it correctly.

后来我解决了问题,因为我对 Project 和 Module 使用了相同的名称,并且看起来 Intellij 允许这样做但无法正确处理它。

No idea why setting will impact the compilation, although there is no error in java editor. Should be a bug in version 13.

不知道为什么设置会影响编译,虽然java编辑器没有错误。应该是版本 13 中的错误。

回答by OhadR

I found out that this might help:

我发现这可能会有所帮助:

File -> Invalidate Caches

文件 -> 无效缓存