Reputation:
I'm trying to include som Kotlin files in a rather large IntelliJ Java project, and I've stumbled upon a case where I get "unresolved reference" on absolutely every import.
The (simplified project structure:
Project:
saksbehandling
- e2e
- cucumber
- src
- test
- java
-e2e
- support
- common
- src
- main
- java
- common
- testdata
Kotlin classes in the support module work fine. Kotlin classes in the common module does not.
The same file is located in the /e2e/cucumber/src/test/java/e2e/support and the /e2e/common/src/main/java/common/testdata folders. In the latter, I get "Unresolved reference" when I try any kind of import. Example:
import api.utils.ApiResourceFactory
import com.google.common.io.Resources
import e2e.utils.AdressIterator
Now, the api.utils an e2e.utils unresolved references are one thing. But the com.google reference? That tells me there's something seriously missing or broken.
I've been looking for conflicting versions etc., but it's all the same project, so how can the problem be related to that? Also, making the common module dependent on the cucumber module does not help, and also that's not a good idea.
Any ideas how to fix this probably silly newbie problem?
BTW: In addition, when creating the Kotlin file in the common module, where no imports work, suddenly a working Kotlin file in the cucumber module also starts getting Unresolved references on things that's been working until the new file was created.
UPDATE:
Using this link: https://www.baeldung.com/kotlin-maven-java-project to tweak the .pom file i was able to get most of the imports working.
However, some strange things are still not working:
import kotlin.collections.ArrayList still gives "Unresolved reference: ArrayLIst"
And in the code, I get "Unresolved reference" on the following
listOf()
educationMap[fnr] (the []'s - No set method providing array access
ComplaiuntWhoEnum::class.java.enumConstants - Unresolved reference: Java
I even get errors about Unresolve reference: Int (!)
UPDATE 2:
If I create a folder /common/src/main/kotlin, things look better. But then I'm unable to import those classes into classes in the cucumber module.
Upvotes: 0
Views: 12798
Reputation: 37829
If your build fails outside of IntelliJ, you should probably start by fixing this. Maybe post the error you're getting and your build configuration to get help.
If everything works outside of IntelliJ IDEA, maybe the configuration of your modules is outdated and IntelliJ struggles to fix it.
2 solutions have worked so far for me when re-organizing modules in IntelliJ:
File > Invalidate caches / Restart
Upvotes: 6