javax.inject imports missing in IntelliJ for Micronaut Kotlin project

huangapple go评论161阅读模式
英文:

javax.inject imports missing in IntelliJ for Micronaut Kotlin project

问题

我想在IntelliJ中使用Kotlin开始使用Micronaut。我可以从GitHub上设置这个示例项目。使用gradle运行项目效果很好。然而,IntelliJ不会让我从javax.inject导入任何注解。编辑器将始终显示import javax.inject.Singleton为编译错误(例如,红色字体)。悬停显示:

> 未解析的引用:Singleton

在项目树中浏览External Libraries,显示了一个依赖项javax.inject:javax.inject:1,应该包含所需的注解,但显示为空文件夹。

由于IntelliJ使用gradle进行构建,因此构建在没有编译错误的情况下正常工作。如文档中所述:在IntelliJ中启用了注解处理。

我是不是漏掉了什么,还是IntelliJ出了问题(版本#IU-202.6397.94,构建日期2020年7月27日,Kotlin插件1.4.0)?

英文:

I wanted to get started with Micronaut using Kotlin in IntelliJ. I can setup this exmaple project from github. Running the project with gradle works just fine. Still IntelliJ will not let me import any annotation from javax.inject. The editor will always display import javax.inject.Singleton as compilation error (e.g. red font). 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.

Since IntelliJ is using gradle for building the build works without compilation error. As mentioned in the docs: annotation processing is enabled in 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)

答案1

得分: 2

Micronaut 3 M2发布

这应该能回答你的问题。如果你喜欢使用javax,将以下内容添加到依赖项中应该会有帮助:

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

Micronaut 3 M2 Released

This should answer your question. Adding this below to dependencies should help if you prefer using javax

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

答案2

得分: 1

自从 Micronaut 3.0 版本开始,Micronaut Gradle 插件会自动添加新的 jakarta.inject 构件。无需显式添加。

尝试在 IntelliJ IDEA 的 终端 窗口中使用命令行构建项目(./gradlew build),然后在 Gradle 窗格中刷新项目。

查看我的示例以演示 Kotlin 和 Kotlin 协程

英文:

Since Micronaut 3.0, micronaut Gradle plugin adds new jakarta.inejct artifact automatically. 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.

Check my example to demo Kotlin and Kotlin Coroutines.

huangapple
  • 本文由 发表于 2020年8月26日 22:22:52
  • 转载请务必保留本文链接:https://go.coder-hub.com/63599741.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定