简体   繁体   English

Gradle 项目构建成功,但 IntelliJ 无法解析引用

[英]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 工作正常。

IntelliJ 的 linter 错误

It altv-kotlin is a fatjar and even includes the sources in the jar: https://gitlab.com/7Hazard/altv-kotlin/-/blob/master/build.gradle#L53altv-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.

相关问题 Intellij Gradle 项目无法使用 junit 4.11 作为 testCompile dep 解析 assertEquals - Intellij Gradle project cannot resolve assertEquals with junit 4.11 as the testCompile dep IntelliJ中的“ java:找不到符号”但gradle构建 - “java: cannot find symbol” in IntelliJ but gradle builds IntelliJ IDEA 中带有 Gradle 的 Java 项目:无法解析符号“google”,但项目可以编译 - Java project with Gradle in IntelliJ IDEA: cannot resolve symbol 'google' but project compiles 无法将Avro导入IntelliJ中的Gradle项目 - Cannot import Avro into a Gradle project in IntelliJ IntelliJ SBT项目无法解析SBT符号 - IntelliJ SBT project cannot resolve SBT symbols Intellij无法在具有多个SourceSet的Gradle Project中解析符号 - Intellij can not resolve Symbol in Gradle Project with multiple SourceSets Gradle 在没有 SourceSet 的情况下成功构建,但使用 SourceSet 失败,错误找不到符号 - Gradle builds successfully without SourceSet, but fails with SourceSet, Error Cannot Find Symbol 无法让 log4j.properties 与 IntelliJ 中的 Gradle 项目一起使用 - Cannot get log4j.properties to work with Gradle project in IntelliJ Intellij Android 项目 Gradle - Intellij Android Project Gradle Netbeans项目成功构建但未运行 - Netbeans project builds successfully but does not run
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM