简体   繁体   English

IntelliJ IDEA Ultimate 2018.3 认为我的 Java 9 项目是 Kotlin 项目

[英]IntelliJ IDEA Ultimate 2018.3 thinks my Java 9 Project is a Kotlin Project

I have an IntelliJ project composing several subprojects which are all Java 9 modules.我有一个 IntelliJ 项目,它由几个都是 Java 9 模块的子项目组成。 I use Maven as a build system.我使用 Maven 作为构建系统。 My project has no "Facets".我的项目没有“方面”。 My run configuration looks like this:我的运行配置如下所示: 运行配置

My project settings look like this:我的项目设置如下所示: 项目设置

I can build everything with Maven just fine.我可以用 Maven 构建一切就好了。 However, when I try to compile with IntelliJ, it somehow thinks that my project is a Kotlin project and can't compile it:但是,当我尝试使用 IntelliJ 进行编译时,它以某种方式认为我的项目是 Kotlin 项目并且无法编译它:

错误信息

Error:Kotlin: The Kotlin standard library is not found in the module graph.错误:Kotlin:在模块图中找不到 Kotlin 标准库。 Please ensure you have the 'requires kotlin.stdlib' clause in your module definition请确保您的模块定义中有“requires kotlin.stdlib”子句

Has anyone any idea how to fix this?有谁知道如何解决这个问题? I already tried deleting the run configuration and recreated it.我已经尝试删除运行配置并重新创建它。 This fixes the problem for some time, but then it reappears randomly.这解决了一段时间的问题,但随后它会随机重新出现。

Even in 2019.1.3 that error is there .即使在2019.1.3中也存在该错误。

A solution that always works for me is :一个总是对我有用的解决方案是:

Build menu => Rebuild Project

Tested with JDK 12.0.1使用 JDK 12.0.1 测试


That should be fixed though by IntelliJ team as soon as possible as more and more Java projects are passing to JDK 11 ++这应该由 IntelliJ 团队尽快修复,因为越来越多的 Java 项目正在传递给 JDK 11++

I had the same problem.我有同样的问题。 I worked in a pure Java project managed with Maven.我在一个用 Maven 管理的纯 Java 项目中工作。 Till some days ago I applied the solution "rebuild" the project, but sometimes the error came back again.直到几天前,我应用了“重建”项目的解决方案,但有时错误又回来了。

After more investigation, I found that after disable "Enable migration detection" menu, the problem disappears.经过更多的调查,我发现禁用“启用迁移检测”菜单后,问题消失了。

禁用菜单 启用迁移检测

I hope this helps.我希望这有帮助。

尝试使用 Ctrl+Shift+F9 重建模块或右键单击模块并在菜单中选择“重建”。

Meanwhile, this can be fixed using the kotlin-stdlib.jar available in Kotlin JavaRuntime:同时,这可以使用 Kotlin JavaRuntime 中提供的kotlin-stdlib.jar修复:

module kotlin.test {
    requires kotlin.stdlib;
}

where kotlin.test should be replaced with your module name.其中kotlin.test应替换为您的模块名称。

Just in case the details matter, I am using以防万一细节很重要,我正在使用

IntelliJ IDEA 2018.3 (Community Edition) Build #IC-183.4284.148, built on November 21, 2018

and the Kotlin JavaRunTime mentioned above has sources from the path Contents/plugins/Kotlin/kotlinc/lib within the IntelliJ .app which includes kotlin-stdlib.jar as one of them.上面提到的 Kotlin JavaRunTime 的来源来自 IntelliJ .app中的路径Contents/plugins/Kotlin/kotlinc/lib ,其中包括kotlin-stdlib.jar作为其中之一。

我遇到了同样的问题,我删除了文件并重新开始,之后它工作正常

我通过禁用 Kotlin 插件修复了这个错误,因为我没有使用它并且问题解决了

Update your module-info.java file更新你的 module-info.java 文件

requires javafx.fxml;
requires javafx.controls;
requires javafx.graphics;
requires javafx.web;

opens sample;

opens sample.controller;

It opens the package (eg. sample) which contains your Launcher file and opens package conatinsyoyr controllers and its corresponding fxml files (eg. sample.controller)它打开包含您的 Launcher 文件的包(例如示例)并打开包 conatinsyoyr 控制器及其相应的 fxml 文件(例如 sample.controller)

I had the same issue.我遇到过同样的问题。 Here is what worked:这是有效的:

  1. On IntellijIDEA go to 'Tools' menu at the top of the application:在 IntellijIDEA 上,转到应用程序顶部的“工具”菜单:IntelliJ IDEA IDE . .
  2. Then scroll down to 'Kotlin'.然后向下滚动到“Kotlin”。
  3. Click 'Configure Kotlin in Project'.单击“在项目中配置 Kotlin”。

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

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