Could not find kotlin-gradle-plugin for Kotlin script Gradle
Asked Answered
W

1

3

build fails, classpath error:

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

The buildfile was a direct copy of a working build. The context is getting started with Kotlin script Gradle. So far as I can tell the script should be good.

Note that I'm not using intelli-J, this is strictly from the CLI with Kotlin script Gradle.

perhaps it's something quite simple, like "plugin" versus "plugins"...

Windsail answered 7/2, 2018 at 12:6 Comment(0)
B
2

Looking at the error logs, you can see the plugin version request:

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

You can see that a version is not requested on each plugin request because they are looking for kotlin-gradle-plugin-.jar.

If you look at the source, you will also see that kotlinModule is deprecated.

I would recommend a few different changes to improve the build script:

  1. Using the Gradle wrapper (./gradlew
  2. Specify a version for your kotlinModule until you upgrade your Gradle version - kotlinModule("gradle-plugin", "1.1.51")
  3. Use the plugins {} block instead of buildscript for plugins
Bandy answered 26/2, 2018 at 17:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.