[英]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.以下 Kotlin 库的每次使用都会编译并可以使用,但 IntelliJ 的自动完成功能(可能还有其他)无法解析引用。 https://gitlab.com/7Hazard/altv-kotlin
https://gitlab.com/7Hazard/altv-kotlin
I am using it as a dependency via JitPack: https://jitpack.io/#com.gitlab.7Hazard/altv-kotlin我通过 JitPack 将其用作依赖项: https://jitpack.io/#com.gitlab.7Hazard/altv-kotlin
JDK 11, Gradle 6.3 (wrapper) JDK 11、Gradle 6.3(包装)
The gradle project builds fine but just autocompletion is broken. gradle 项目构建良好,但只是自动完成功能被破坏。 Other dependencies like kotlinx.coroutines work fine.
其他依赖项,如 kotlinx.coroutines 工作正常。
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它
altv-kotlin
是一个胖子,甚至包括 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. 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?难道是因为某种原因没有正确地将源放入 JAR 中? I couldn't even get IDEA to decompile the references for autocompletion.
我什至无法让 IDEA 反编译自动完成的引用。 I have a strong feeling this is an issue tied to
altv-kotlin
library specifically, and not any of my environment setup.我有一种强烈的感觉,这是一个与
altv-kotlin
库相关的问题,而不是我的任何环境设置。
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.我尝试删除.idea 文件夹,使缓存无效/重新启动,为 IDEA 和 gradle 项目更新 Kotlin 插件,甚至将 IDEA 从 2018 年更新到 2020 年,但无济于事。 I tried these answers as well but did not solve the problem:
我也尝试了这些答案,但没有解决问题:
https://stackoverflow.com/a/56619181/8122837 https://stackoverflow.com/a/56619181/8122837
https://stackoverflow.com/a/5905931/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.我还注意到有关 Kotlin Runtime 与库捆绑的警告,但即使没有捆绑在其中,IDEA 也会抱怨。
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.但是,当使用来自 JitPack 的远程依赖项时,因为我将 JAR 中的所有类文件都包含在内,以使其成为一个 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.自从我从
jar
任务中删除该行后,IntelliJ IDEA 就能够正常解析引用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.