【问题标题】:Could not find kotlin-gradle-plugin for Kotlin script Gradle找不到 Kotlin 脚本 Gradle 的 kotlin-gradle-plugin
【发布时间】:2018-07-17 17:18:06
【问题描述】:

构建失败,类路径错误:

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。上下文从Kotlin script Gradle 开始。据我所知,脚本should be good

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

也许这是相当 simple 的东西,比如“插件”与“插件”...

【问题讨论】:

    标签: kotlin uberjar gradle-kotlin-dsl shadowjar


    【解决方案1】:

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

    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. 在升级 Gradle 版本之前为您的 kotlinModule 指定一个版本 - kotlinModule("gradle-plugin", "1.1.51")
    3. 为插件使用plugins {} 块而不是buildscript

    【讨论】:

      猜你喜欢
      • 2020-01-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-12-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多