Hello
I’m trying to migrate a small project from the groovy build to the kotlin dsl. The new migration guide https://guides.gradle.org/migrating-build-logic-from-groovy-to-kotlin/ helped a lot!
I struggle with migrating the jacoco plugin where I configure the destinationPath to re-use it for sonar and teamcity. But I can’t figure out how to set the destinationFile in build.gradle.kts:
import com.palantir.gradle.docker.DockerExtension
import org.gradle.api.internal.GradleInternal
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import org.gradle.testing.jacoco.plugins.JacocoTaskExtension
import org.springframework.boot.gradle.tasks.bundling.BootJar
val kotlinVersion = "1.2.51"
plugins {
val kotlinVersion = "1.2.51"
kotlin("jvm") version kotlinVersion
kotlin("plugin.spring") version kotlinVersion
// id("org.jetbrains.kotlin.jvm") version "1.2.51"
// id("org.jetbrains.kotlin.plugin.spring") version "1.2.51"
jacoco
id("org.springframework.boot") version "2.0.3.RELEASE"
id("io.spring.dependency-management") version "1.0.6.RELEASE"
id("com.palantir.docker") version "0.20.1"
id("org.sonarqube") version "2.6.2"
}
val version = System.getenv("BUILD_NUMBER") ?: "9.0.0-SNAPSHOT"
val sourceCompatibility = 1.8
dependencies {
// ...
}
val jacocoExecFileName = "${rootProject.buildDir}/jacoco/exec/test.exec"
val jacocoExecFileNameIt = "${rootProject.buildDir}/jacoco/exec/itTest.exec"
tasks {
jacoco {
// destination
// destinationFile = file(jacocoExecFileName)
}
sonarqube {
properties {
property("sonar.projectName", "DWH ETL Service")
property("sonar.projectKey", "ch.mobi.jap:dwh-etl-service")
property("sonar.jacoco.reportPath", jacocoExecFileName)
property("sonar.jacoco.itReportPath", jacocoExecFileNameIt)
}
}
"printJacacoInfoForTeamcity" {
doLast {
val classpath = "+:build/classes/kotlin/main/**"
val includes = "ch.mobi.dwh.*"
println("##teamcity[jacocoReport dataPath='$jacocoExecFileName' includes='$includes' classpath='$classpath']")
}
}
}
//configure<JacocoTaskExtension> {
// destinationFile = file(jacocoExecFileName)
//}
tasks.withType<Test> {
configure<JacocoTaskExtension> {
destinationFile = file(jacocoExecFileName) // val cannot be reassigned
}
}
tasks.withType<Test> {
jacoco {
destinationFile = file(jacocoExecFileName) // unresolved reference: destinationFile
}
}
val bootJar: BootJar by tasks
//bootJar.baseName = "dwh-etl-service"
//bootJar.version = "0.0.1"
configure<DockerExtension> {
name = "docker-registry.mobicorp.ch/mobi/dwh/dwh-etl-service:$version"
files(bootJar.archivePath)
buildArgs(mapOf("JARFILE" to bootJar.archiveName, "VERSION" to version))
dependsOn(tasks["build"])
tags("latest")
}
The only related (?) issue I found was https://github.com/gradle/kotlin-dsl/issues/681
I put the error I get (lines 68 and 74) in comments. Is there a way to do this? Or are these plugin (or task?) extensions not yet working?
Thanks!