Gradle 中出现 ModuleVersionNotFoundException 的原因是什么?

Dan*_*uso 5 java intellij-idea gradle

我以前使用过Gradle,但从未亲自配置过。我正在运行 openjdk 11.0.4 并使用官方安装指南安装了 Gradle,包括将其添加到 Windows 路径。我所做的就是添加一行:'''

implementation 'com.github.kittinunf.fuel:fuel:2.2.0'
Run Code Online (Sandbox Code Playgroud)

到我的 build.gradle 文件。我正在使用 Intellij 进行编辑。这是我的完整 build.gradle 文件:

plugins {
    id 'java'
    id 'org.jetbrains.kotlin.jvm' version '1.3.61'
}

group 'lastname'
version '1.0-SNAPSHOT'

sourceCompatibility = 1.8

repositories {
    mavenCentral()
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
    testCompile group: 'junit', name: 'junit', version: '4.12'
    implementation 'com.github.kittinunf.fuel:fuel:2.2.0'
}

compileKotlin {
    kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
    kotlinOptions.jvmTarget = "1.8"
}
Run Code Online (Sandbox Code Playgroud)

当我尝试同步项目时,我从 Gradle 选项卡 gradle_tab_view中收到以下内容

我得到的构建输出是这样的:

4:20:29 PM: Executing tasks ':classes :testClasses'...

> Task :compileKotlin FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':compileKotlin'.
> Could not resolve all files for configuration ':compileClasspath'.
   > Could not find com.github.kittinunf.fuel:fuel:2.2.0.
     Searched in the following locations:
       - https://repo.maven.apache.org/maven2/com/github/kittinunf/fuel/fuel/2.2.0/fuel-2.2.0.pom
       - https://repo.maven.apache.org/maven2/com/github/kittinunf/fuel/fuel/2.2.0/fuel-2.2.0.jar
     Required by:
         project :

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 0s
1 actionable task: 1 executed
4:20:30 PM: Tasks execution finished ':classes :testClasses'.
Run Code Online (Sandbox Code Playgroud)

任何有关可能被破坏或明显未实施的内容的建议将不胜感激,这极大地阻碍了我的工作流程,而且我觉得它一定是我忽略的小或愚蠢的东西。我觉得我正在与 Gradle 交战,让 Fuel 在我的项目中发挥作用。

Bjø*_*ter 3

错误输出意味着 Gradle 无法在搜索的两个位置中找到 Fuel 依赖项。这两个位置都位于https://repo.maven.apache.org/maven2/Maven Central 中。Gradle 按照您的指示通过 查找此存储库repositories { mavenCentral() }。

但是,Fuel 未发布到 Maven Central。如果您使用像mvnrepository这样的搜索网站,您将看到它是在哪里找到的。在这种情况下,它说:

注意:这个工件位于 Spring Lib Release 存储库(https://repo.spring.io/libs-release/)

但他的说法具有误导性,因为这只是一面镜子,因为某些 Spring 库显然依赖于它。如果您访问Fuel 的Github页面,您将看到它实际上已部署到Jitpack。所以正确的解决方案是将 Jitpack 添加到 Gradle 中的存储库列表中:

repositories {
    maven {
        name "jitpack"
        url "https://www.jitpack.io"
    }
}
Run Code Online (Sandbox Code Playgroud)

这在 Github 页面上并不是很清楚,因为仅在快照版本部分中进行了解释。但是,当给定依赖项不存在于任何常见依赖项中时,必须做一些侦探工作来追踪哪个存储库用于该依赖项,这种情况并不少见。

顺便说一句,testCompile已弃用,您应该使用testImplementation. 由于这是一个 Kotlin 项目,您可能希望在某个时候从 Groovy DSL 切换到 Kotlin DSL。