简体   繁体   English

用于 Micronaut Kotlin 项目的 IntelliJ 中缺少 javax.inject 导入

[英]javax.inject imports missing in IntelliJ for Micronaut Kotlin project

I wanted to get started with Micronaut using Kotlin in IntelliJ.我想在 IntelliJ 中使用 Kotlin 开始使用 Micronaut。 I can setup this exmaple project from github .我可以从 github设置这个 exmaple 项目 Running the project with gradle works just fine.使用 gradle 运行项目效果很好。 Still IntelliJ will not let me import any annotation from javax.inject . IntelliJ 仍然不会让我从javax.inject导入任何注释。 The editor will always display import javax.inject.Singleton as compilation error (eg red font).编辑器将始终将import javax.inject.Singleton显示为编译错误(例如红色字体)。 Mouse over displays鼠标悬停在显示器上

Unresolved reference: Singleton未解决的参考:单例

Browsing External Libraries in the project tree shows a dependency javax.inject:javax.inject:1 that should contain said annotations but it is displayed as empty folder. Browsing External Libraries在项目树中显示了一个依赖javax.inject:javax.inject:1应该包含所述注释但它显示为空文件夹。

Since IntelliJ is using gradle for building the build works without compilation error.由于 IntelliJ 使用 gradle 来构建构建工作而不会出现编译错误。 As mentioned in the docs: annotation processing is enabled in IntelliJ.如文档中所述:在 IntelliJ 中启用了注释处理。

Am I missing something or is this broken in IntelliJ (Build #IU-202.6397.94, built on July 27, 2020, Kotlin plugin 1.4.0)我是不是遗漏了什么,或者这在 IntelliJ 中被破坏了(Build #IU-202.6397.94,构建于 2020 年 7 月 27 日,Kotlin 插件 1.4.0)

Micronaut 3 M2 Released Micronaut 3 M2 发布

This should answer your question.这应该回答你的问题。 Adding this below to dependencies should help if you prefer using javax如果您更喜欢使用 javax,将下面的添加到依赖项应该会有所帮助

implementation("javax.inject:javax.inject:1")

Since Micronaut 3.0, micronaut Gradle plugin adds new jakarta.inejct artifact automatically.从 Micronaut 3.0 开始,micronaut Gradle 插件会自动添加新的jakarta.inejct工件。 No need add it explicitly.无需明确添加。

Try to build the project by command line( ./gradlew build ) in Intellij IDEA terminal windows, then refresh the project in the Gradle pane.尝试在 Intellij IDEA终端窗口中通过命令行( ./gradlew build )构建项目,然后在 Gradle 窗格中刷新项目。

Check my example to demo Kotlin and Kotlin Coroutines .查看我的示例以演示Kotlin 和 Kotlin Coroutines

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

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