3

构建失败,类路径错误:

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"
}

构建文件是工作构建的直接副本。上下文是从Kotlin 脚本 Gradle开始的。据我所知,剧本应该不错

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

也许这很简单,比如“插件”与“插件”......

4

1 回答 1

2

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

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.

如果您查看源代码,您还会看到它kotlinModule已被弃用。

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

  1. 使用 Gradle 包装器 (./gradlew
  2. kotlinModule在升级 Gradle 版本之前为您指定一个版本 -kotlinModule("gradle-plugin", "1.1.51")
  3. 使用plugins {}块而不是buildscript插件
于 2018-02-26T17:05:14.970 回答