Java 是什么导致Gradle中出现ModuleVersionNotFoundException?
我以前使用过Gradle,但从未亲自配置过。我正在运行openjdk 11.0.4,并使用官方安装指南安装了Gradle,包括将其添加到windows路径。我一直在做的就是添加一行: ''' 到我的build.gradle文件。我正在使用Intellij进行编辑。这是我的完整build.gradle文件:Java 是什么导致Gradle中出现ModuleVersionNotFoundException?,java,gradle,intellij-idea,Java,Gradle,Intellij Idea,我以前使用过Gradle,但从未亲自配置过。我正在运行openjdk 11.0.4,并使用官方安装指南安装了Gradle,包括将其添加到windows路径。我一直在做的就是添加一行: ''' 到我的build.gradle文件。我正在使用Intellij进行编辑。这是我的完整build.gradle文件: plugins { id 'java' id 'org.jetbrains.kotlin.jvm' version '1.3.61' } group 'lastname' v
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"
}
当我尝试同步项目时,我从我的Gradle选项卡获得以下内容
我得到的构建输出如下:
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'.
任何关于哪些内容可能会被破坏或者哪些内容显然没有得到实施的建议都将受到赞赏,这极大地阻碍了我的工作流程,我觉得这一定是我忽略了的一些小的或愚蠢的事情。我觉得我在与Gradle争夺项目的燃料。错误输出意味着Gradle无法在搜索的两个位置找到燃料依赖关系。两个位置都位于
https://repo.maven.apache.org/maven2/
,即Maven Central。Gradle会按照您通过存储库{mavenCentral()}
告诉它的那样查看此存储库
但是,燃料并未发布给Maven Central。如果你使用像这样的搜索网站,你会看到它是在哪里找到的。在这种情况下,它说:
注意:此工件位于SpringLib发行版存储库中
()
但他的观点是误导性的,因为这只是一面镜子,一些Spring库显然依赖于它。如果您转到页面查找Fuel,您将看到它实际上已部署到。因此,正确的解决方案是将Jitpack添加到Gradle中的存储库列表中:
repositories {
maven {
name "jitpack"
url "https://www.jitpack.io"
}
}
这在Github页面中并不是很清楚,这一点只在快照发布部分进行了解释。但是,当一个给定的依赖项不存在于任何常见的依赖项中时,需要做一些检测工作来跟踪该依赖项要使用的存储库,这并不少见
顺便说一下,testCompile
已被弃用,您应该使用testImplementation
。由于这是一个Kotlin项目,您可能希望在某个时候从Groovy DSL切换到Kotlin DSL
repositories {
maven {
name "jitpack"
url "https://www.jitpack.io"
}
}