Skip to content

Commit

Permalink
chore: fix sonar setup (#197)
Browse files Browse the repository at this point in the history
  • Loading branch information
ursjoss authored Oct 7, 2023
1 parent 487c2cf commit 45f6964
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 7 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,11 @@ jobs:
name: reports
path: '**/build/reports'

- name: Run all tests with Gradle
run: ./gradlew check sonar --no-daemon
- name: Re-run all tests with Gradle
run: ./gradlew check

- name: Report analysis to sonar
run: ./gradlew sonar
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
22 changes: 18 additions & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ plugins {
jacoco
}

val jacocoTestReportFile = "${layout.buildDirectory.get()}/reports/jacoco/test/jacocoTestReport.xml"

jacoco {
toolVersion = libs.versions.jacoco.get()
}
Expand All @@ -35,8 +33,6 @@ sonarqube {
property("sonar.host.url", "https://sonarcloud.io")
property("sonar.projectKey", "ursjoss_${project.name}")
property("sonar.organization", "ursjoss-github")
property("sonar.coverage.jacoco.xmlReportPaths", jacocoTestReportFile)
property("sonar.kotlin.detekt.reportPaths", "${layout.buildDirectory.get()}/reports/detekt/detekt.xml")
}
}

Expand Down Expand Up @@ -85,6 +81,24 @@ kotlin {
val kotlinSrcSet = "/src/main/kotlin"

subprojects.forEach { subProject ->
if (subProject.name in setOf("kris-core", "kris-io")) {
apply {
plugin("org.sonarqube")
plugin("jacoco")
}
sonarqube {
properties {
property(
"sonar.kotlin.detekt.reportPaths",
subProject.layout.buildDirectory.get().asFile.resolve("reports/detekt/detekt.xml")
)
property(
"sonar.coverage.jacoco.xmlReportPaths",
subProject.layout.buildDirectory.get().asFile.resolve("reports/jacoco/test/jacocoTestReport.xml")
)
}
}
}
subProject.tasks {
val kotlinVersion = libs.versions.kotlin.get()
val kotlinApiLangVersion = kotlinVersion.subSequence(0, 3).toString()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import org.gradle.testing.jacoco.plugins.JacocoPlugin
import org.gradle.testing.jacoco.plugins.JacocoReportAggregationPlugin
import org.gradle.testing.jacoco.tasks.JacocoReport

@Suppress("unused")
@Suppress("unused", "UnstableApiUsage")
class KrisJacocoPlugin : Plugin<Project> {

override fun apply(target: Project) {
Expand All @@ -26,6 +26,7 @@ class KrisJacocoPlugin : Plugin<Project> {
}
target.rootProject.tasks.named("sonar") {
dependsOn(tasks.getByName("check"))
dependsOn(tasks.getByName("jacocoTestReport"))
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ group=ch.difty.kris
org.gradle.jvmargs=-XX:MaxMetaspaceSize=1G

org.gradle.kotlin.dsl.allWarningsAsErrors=true

systemProp.sonar.gradle.skipCompile=true
4 changes: 4 additions & 0 deletions subprojects/kris-core/kris-core.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,8 @@ tasks {
named("sourcesJar") {
dependsOn(javadocJar)
}
val apiBuild by existing
named("jacocoTestReport") {
dependsOn(apiBuild)
}
}
11 changes: 11 additions & 0 deletions subprojects/kris-io/kris-io.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,17 @@ tasks {
named("sourcesJar") {
dependsOn(javadocJar)
}
val apiBuild by existing
named("jacocoTestReport") {
dependsOn(testing.suites.named("integrationTest"))
dependsOn(apiBuild)
rootProject.subprojects.firstOrNull { it.name == "kris-core" }?.tasks?.named("test")?.let {
dependsOn(it)
}
rootProject.subprojects.firstOrNull { it.name == "kris-core" }?.tasks?.named("apiBuild")?.let {
mustRunAfter(it)
}
}
}

dependencies {
Expand Down

0 comments on commit 45f6964

Please sign in to comment.