External class in Kotlin project can't be resolved when using Kotlin, but can be resolved when using Java

Answered

I have a project called "Virtue" that is separate to the project "Base". "Base" is a dependency to "Virtue".

When using Kotlin in Virtue, the project cannot identify the Kotlin singleton "rip.paragon.base.Base" even though it is added as a Maven dependency:

 

However, when using Java in Virtue, the class is resolved just fine:

 

 

 

Keep in mind Base is coded in Kotlin and contains no Java code whatsoever.

TLDR: Project cannot identify a class in an external library when using Kotlin but it can resolve it when using Java. Not sure how to fix, can't find a solution online. My POM is setup correctly and the external JAR shows up fine under external libraries.

0
11 comments

Something else I should mention, I can use Java external libraries just fine when using Kotlin, but cannot use Kotlin + Kotlin together.

0

Hello Levi,

Have you tried to run "File | Invalidte Caches"? If it doesn't help please create new issue on YouTrack: https://youtrack.jetbrains.com/issues/KT

0

Hi, I tried that last night, although it seems after restarting my PC and invalidating caches again it seems to work now. I assume it was some bug related to Maven. I'll post it on YouTrack if it re-occurs. Thanks for the help.

0

I'm having the exact same issue again since the original post. I've tried restarting my PC and invalidating caches, deleting the .idea and .iml file, and have tried deleting the LocalHistory and caches folder (there was one other folder too, forgot what it's called) nothing has worked.

Running IntelliJ Ultimate 2019.3 stable build, I have also tried disabling every plugin but Kotlin and .ignore, still not importing correctly.

The project compiles on my PC with Maven fine in the same project directory and it also compiles fine on the CI server I have setup for this project. I have a remote repository defined in the POM which 100% works fine also and I can download artifacts from the server just fine. I'm using Maven 3.6.1. I've also tried nuking the local repository folder (in the .m2 folder) and hasn't worked.

To clarify, the dependency is imported just fine in the POM and on the dependencies list (in the "external libraries" section) there's no red lines or anything. Every other dependency imports fine besides one; this dependency is 99% Kotlin code and everything else is 100% Java, so I'm certain it's something to do with the original issue (not being able to use external Kotlin classes inside Kotlin classes).

0

Hey Levi Taylor,

I think i'm having the same issue here, but its suddenly happening where it was fine before, the only change being I changed the java version from 8 to 11, but trying reverting back now leaves me with the same problem.

I've tried all proposed solutions, did you manage to fix this?

 

1

Julioevm, Did you created the issue as requested? I'm facing the same problem and the use of Java 11 looks like to be the cause.

0

Hi Lbernardomaia, Yeah I created the issue: https://youtrack.jetbrains.com/issue/KT-38671

Sadly, it was closed since they couldn't reproduce it. The workaround I had to make was to rename the class that was giving me trouble, after changing its name everything worked fine.

 

0

Julioevm, thought it was worth mentioning here since I fixed this a long time ago; the issue I had was that I had the Kotlin std-lib compiling with my dependency (in my case, Base.) When I tried to use the dependency in my project (Virtue) it wouldn't detect Kotlin classes. I think this is probably a bug, I don't see why this would be intentional. If you're using Kotlin std-lib, or any other Kotlin dependencies, I suggest making their scope as "provided" so they don't compile with your dependency. Then try use the dependency again.

I suggest invalidating caches and restarting as well.

0

Please sign in to leave a comment.