Skip to content
Advertisement

Gradle project builds successfully but IntelliJ cannot resolve references

Every usage of the following Kotlin library compiles and can be used, but IntelliJ’s autocomplete (and perhaps others) cannot resolve the references. https://gitlab.com/7Hazard/altv-kotlin

I am using it as a dependency via JitPack: https://jitpack.io/#com.gitlab.7Hazard/altv-kotlin
JDK 11, Gradle 6.3 (wrapper)

The gradle project builds fine but just autocompletion is broken. Other dependencies like kotlinx.coroutines work fine.

IntelliJ's linter error

It altv-kotlin is a fatjar and even includes the sources in the jar: https://gitlab.com/7Hazard/altv-kotlin/-/blob/master/build.gradle#L53
It in turn uses a java dependency, so altv-kotlin uses some Java and the end fatjar includes both Kotlin and Java sources if that makes a difference.

Could it be that the source are not being put in the JAR correctly for some reason? I couldn’t even get IDEA to decompile the references for autocompletion. I have a strong feeling this is an issue tied to altv-kotlin library specifically, and not any of my environment setup.

I’ve tried to delete the .idea folder, Invalidate Caches / Restart, update Kotlin plugin for both IDEA and gradle projects and even updated IDEA from 2018 to 2020 with no avail whatsoever. I tried these answers as well but did not solve the problem:
https://stackoverflow.com/a/56619181/8122837
https://stackoverflow.com/a/5905931/8122837
I also noticed the warning about Kotlin Runtime being bundled with the library, but even without it being bundled in it IDEA complains.

Advertisement

Answer

So, locally I seem to have resolved the issue by recreating the project and copying the sources into there. Seems to have worked, why I don’t know.
However, when using the remote dependency from JitPack, because I was including all the classfiles in the JAR to have it be a fatjar.

jar {
    from configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it)
}

Ever since I removed that line from the jar task, IntelliJ IDEA was able to resolve the references normally.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement