Emile Achadde
Emile Achadde

Reputation: 1815

Gradle : why this build.gradle.kts script fails to produce any java class?

Below is a build.gradle.kts script which applies to kotlin code located at src/main/kotlin.

It is an attempt of the translation from a groovy script which runs correctly.

The gradlew build steps has no error, but fails to produce any java class from the kotlin code. What instruction is missing ?

buildscript {

    repositories {
        jcenter()
    }

    dependencies {
        classpath(kotlin("gradle-plugin", version = "1.2.70"))   
        classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.2.70")
        classpath("com.github.ben-manes:gradle-versions-plugin:0.20.0")
    }
}

plugins {
    jacoco
    java
    application
    "com.github.ben-manes.versions"
}

java {
    sourceCompatibility = JavaVersion.VERSION_1_8
    targetCompatibility = JavaVersion.VERSION_1_8
}

jacoco {
 toolVersion = "0.8.1"
}

repositories {
    jcenter()
}

dependencies {
    implementation("org.jetbrains.kotlin:kotlin-stdlib:1.2.70")
    implementation("com.squareup.moshi:moshi:1.4.0")
    implementation("com.squareup.okhttp3:okhttp:3.11.0")

    testImplementation("junit:junit:4.12")
    testImplementation("org.mockito:mockito-core:2.12.0")
    testImplementation("com.squareup.okhttp3:mockwebserver:3.11.0")
    testImplementation("org.assertj:assertj-core:3.10.0")
}

application {
    mainClassName = "io.ipfs.kotlin.MainKt"
}

Upvotes: 1

Views: 406

Answers (1)

madhead
madhead

Reputation: 33384

You've added the Kotlin plugin to the build script here:

buildscript {
    repositories {
        jcenter()
    }

    dependencies {
        classpath(kotlin("gradle-plugin", version = "1.2.70"))   
        classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.2.70")
        classpath("com.github.ben-manes:gradle-versions-plugin:0.20.0")
    }
}

but you have not applied it

plugins {
    jacoco
    java
    application
    "com.github.ben-manes.versions"
    // No kotlin plugin actually applied here!
}

Actually, buildscript Kotlin configuration is not needed, as the Kotlin plugin is published to the Gradle's plugins directory. So you can just apply it as simple as:

plugins {
    kotlin("jvm").version("1.2.70")
}

Upvotes: 1

Related Questions