Kotlin-compiler compileOnly dependency clashes with `ApplicationManager.getApplication().restart()` Follow
Hi,
I added a Kotlin LineMarkerProvider to my plugin which reads a specific annotation in given kotlin file and adds a gutter icon. This line marker provider implementation uses the following classes to process the annotation present inside the kotlin file.
org.jetbrains.kotlin.psi.KtAnnotationEntry
org.jetbrains.kotlin.psi.KtExpression
So I added,
compileOnly "org.jetbrains.kotlin:kotlin-compiler:1.3.11"
as a dependency to resolve the above references during compile time as the IDE will provide them during runtime. I also included
<depends>org.jetbrains.kotlin</depends>
in my plugin.xml to make sure that the IDE has kotlin support.
It all works as expected. But I have an unexpected side effect. I have another feature in the same plugin which restarts IDE in some cases using
ApplicationManager.getApplication().restart()
Now this line fails to compile with the following error,
Unresolved reference: restart
If I remove the dependency compileOnly "org.jetbrains.kotlin:kotlin-compiler:1.3.11" then the plugin compiles the code to restart. But without that dependency, I cannot use `org.jetbrains.kotlin.psi.KtAnnotationEntry` and `org.jetbrains.kotlin.psi.KtExpression` inside the LineMarkerProvider implementation.
Can you please provide some input?
Thanks in advance,
Bala
Please sign in to leave a comment.
I did try to invalidate caches and restart. But it din't resolve it.
I created a sample public repo in github to demonstrate this issue. Hope it will be helpful to understand this issue.
Repository : https://github.com/balachandarlinks/IntelliJPluginKotlinCompilerDepIssue
Commit 1 : 73b1774b8383d5e54245dec2e349602dd848f94b - Just an empty plugin created using IntelliJ. Plugin compiles.
Commit 2: 5f4470a20f7ff433b3f88526de96ac9475858574 - Added a class which contains the API call `ApplicationManager.getApplication().restart()`. Also added another call using `ApplicationManagerEx`. Plugin compiles.
Commit 3: 15cdf0de472724af858c8d3b5998364d98bea352 - Added a compileOnly dependency to kotlin compiler. Plugin fails to compile now.
You should refer to Kotlin plugin in version that is packaged with target IDE version in your build.gradle
Remove this line in "dependencies"
compileOnly "org.jetbrains.kotlin:kotlin-compiler:1.3.41"
and change "intellij" block to
It solved it. Thanks @YannCebron :)