In a newly created project via freshly installed IntelliJ IDEA, I create simple scratch kotlin file with simple coroutine. The code works well in the “interactive window” (the one on the right, if I named it correctly), and the syntax highlighting does not complain about anything. But when I press run “current file” (shift + f10) configuration, I got error: unresolved reference: kotlinx
in output window.
- I installed new version of IntelliJ IDEA.
- Created standard Kotlin project on JDK 17, with Gradle on Groovy DSL and named it ScratchTest (in org.example namespace).
- Added
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.2'
to build.gradle. - Created scratch file with ‘use classpath of module’ checkbox.
- Entered a sample code and ran into the problem described above. Look screenshots below. Specific code don’t really matter, the problem is more general, for example I can’t refer functions in my
org.example.ScratchTest
.
Code works in “interactive window”
But failed to compile
There is workaround if I make custom run configuration with specific classpathes.
For example, if I add next argument to run configuration (sample code refers kotlinx.coroutines.runBlocking
) it would compile and work:
-cp C:SomeFolderkotlinx-coroutines-core-jvm-1.5.2.jar
but it’s not very nice solution, especially takin into account the fact the class was originally located in some random folder like %userprofile%.gradlecachesmodules-2files-2.1org.jetbrains.kotlinxkotlinx-coroutines-core-jvm1.5.2f4cc07a50437659e0043e7da762809a46932b6a0kotlinx-coroutines-core-jvm-1.5.2.jar.
Is there easier way to resolve this problem? I remember that it worked before without any difficulties (am I delusional?)
Vladimir Zozulya is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.