找不到 Kotlin-gradle-Kotlin 脚本的插件 Gradle

Could not find kotlin-gradle-plugin for Kotlin script Gradle

构建失败,类路径错误:

thufir@dur:~/NetBeansProjects/kotlinShadowJar$ 
thufir@dur:~/NetBeansProjects/kotlinShadowJar$ gradle clean

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring root project 'kotlinShadowJar'.
> Could not resolve all files for configuration ':classpath'.
   > Could not find org.jetbrains.kotlin:kotlin-gradle-plugin:.
     Searched in the following locations:
         file:/home/thufir/.gradle/caches/4.3.1/embedded-kotlin-repo-1.1.51-1/repo/org/jetbrains/kotlin/kotlin-gradle-plugin//kotlin-gradle-plugin-.pom
         file:/home/thufir/.gradle/caches/4.3.1/embedded-kotlin-repo-1.1.51-1/repo/org/jetbrains/kotlin/kotlin-gradle-plugin//kotlin-gradle-plugin-.jar
         https://repo1.maven.org/maven2/org/jetbrains/kotlin/kotlin-gradle-plugin//kotlin-gradle-plugin-.pom
         https://repo1.maven.org/maven2/org/jetbrains/kotlin/kotlin-gradle-plugin//kotlin-gradle-plugin-.jar
         https://repo.gradle.org/gradle/repo/org/jetbrains/kotlin/kotlin-gradle-plugin//kotlin-gradle-plugin-.pom
         https://repo.gradle.org/gradle/repo/org/jetbrains/kotlin/kotlin-gradle-plugin//kotlin-gradle-plugin-.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.

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

BUILD FAILED in 1s

cat build.gradle.kts:

import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar

buildscript {
    repositories {
        mavenCentral()
        gradleScriptKotlin()
    }
    dependencies {
        classpath(kotlinModule("gradle-plugin"))
        classpath("com.github.jengelman.gradle.plugins:shadow:1.2.3")
    }
}

apply {
    plugin("kotlin")
    plugin("com.github.johnrengelman.shadow")
}

repositories {
    mavenCentral()
}

val shadowJar: ShadowJar by tasks
shadowJar.apply {
    manifest.attributes.apply {
        put("Implementation-Title", "Gradle Jar File Example")
        put("Implementation-Version" version)
        put("Main-Class", "com.mkyong.DateUtils")
    }

    baseName = project.name + "-all"
}

构建文件是 direct copy of a working build. The context is getting started with . So far as I can tell the script

请注意,我没有使用 intelli-J,这完全来自 CLI 和 Kotlin 脚本 Gradle。

也许是相当 的东西,比如 "plugin" 与 "plugins"...

查看错误日志,可以看到插件版本要求:

Searched in the following locations:
     file:/home/thufir/.gradle/caches/4.3.1/embedded-kotlin-repo-1.1.51-1/repo/org/jetbrains/kotlin/kotlin-gradle-plugin//kotlin-gradle-plugin-.pom
     file:/home/thufir/.gradle/caches/4.3.1/embedded-kotlin-repo-1.1.51-1/repo/org/jetbrains/kotlin/kotlin-gradle-plugin//kotlin-gradle-plugin-.jar
     https://repo1.maven.org/maven2/org/jetbrains/kotlin/kotlin-gradle-plugin//kotlin-gradle-plugin-.pom
     https://repo1.maven.org/maven2/org/jetbrains/kotlin/kotlin-gradle-plugin//kotlin-gradle-plugin-.jar
     https://repo.gradle.org/gradle/repo/org/jetbrains/kotlin/kotlin-gradle-plugin//kotlin-gradle-plugin-.pom
     https://repo.gradle.org/gradle/repo/org/jetbrains/kotlin/kotlin-gradle-plugin//kotlin-gradle-plugin-.jar

您可以看到每个插件请求都没有请求一个版本,因为他们正在寻找 kotlin-gradle-plugin-.jar

如果您 look at the source,您还会看到 kotlinModule 已弃用。

我会推荐一些不同的更改来改进构建脚本:

  1. 使用 Gradle 包装器(./gradlew
  2. 为您的 kotlinModule 指定一个版本,直到您升级 Gradle 版本 - kotlinModule("gradle-plugin", "1.1.51")
  3. 对插件使用 plugins {} 块而不是 buildscript