Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

javax.inject imports missing in IntelliJ for Micronaut Kotlin project

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)

like image 725
cmoetzing Avatar asked Oct 15 '25 15:10

cmoetzing


2 Answers

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")
like image 103
Kr10n1 Avatar answered Oct 17 '25 05:10

Kr10n1


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.

like image 28
Hantsy Avatar answered Oct 17 '25 04:10

Hantsy