diff --git a/src/main/kotlin/com/ekino/oss/gradle/plugin/quality/QualityPlugin.kt b/src/main/kotlin/com/ekino/oss/gradle/plugin/quality/QualityPlugin.kt index b0e71fc..9ca5089 100644 --- a/src/main/kotlin/com/ekino/oss/gradle/plugin/quality/QualityPlugin.kt +++ b/src/main/kotlin/com/ekino/oss/gradle/plugin/quality/QualityPlugin.kt @@ -26,7 +26,7 @@ import org.gradle.testing.jacoco.tasks.JacocoReport import org.sonarqube.gradle.SonarExtension import org.sonarqube.gradle.SonarQubePlugin -class QualityPlugin: Plugin { +class QualityPlugin : Plugin { override fun apply(project: Project) { with(project) { @@ -50,14 +50,16 @@ class QualityPlugin: Plugin { } // Jacoco configuration - val jacocoTestReports = tasks.withType { - doFirst { - println("Generating jacoco coverage report in HTML ...") - } - reports { - xml.required.set(true) - csv.required.set(false) - html.required.set(true) + val jacocoTestReports = tasks.withType().also { + it.configureEach { + doFirst { + println("Generating jacoco coverage report in HTML ...") + } + reports { + xml.required.set(true) + csv.required.set(false) + html.required.set(true) + } } } @@ -66,12 +68,10 @@ class QualityPlugin: Plugin { mustRunAfter(jacocoTestReports) } - tasks.named("build") { - dependsOn(jacocoTestReports, printCoverage) - } - if (project.hasProperty("sonarCoverageExclusions")) { - val excludes = (findProperty("sonarCoverageExclusions") as String).replace(".java", ".class").split(",\\s*".toRegex()) + val excludes = (findProperty("sonarCoverageExclusions") as String) + .replace(".java", ".class") + .split(",\\s*".toRegex()) afterEvaluate { jacocoTestReports.configureEach { classDirectories.setFrom(sourceSets["main"].output.classesDirs.asFileTree.matching { @@ -81,6 +81,10 @@ class QualityPlugin: Plugin { } } + tasks.named("build") { + dependsOn(jacocoTestReports, printCoverage) + } + // Sonar configuration configure { properties { @@ -96,7 +100,7 @@ class QualityPlugin: Plugin { } internal fun getCheckstyleConfig() = getFilePath()?.use { String(it.readBytes()) } - ?: throw MissingResourceException("The checkstyle config file cannot be found") + ?: throw MissingResourceException("The checkstyle config file cannot be found") internal fun getFilePath() = QualityPlugin::class.java.classLoader?.getResourceAsStream("checkstyle.xml")