TLDR: How do I configure sonarqube-gradle-plugin
with GitHub Actions and actions@setup-java
set to JDK 8 for project’s compatibility testing/building?
When testing in GitHub actions with java matrix set to 8
, 11
, 17
, 19
.
All runs just fine except the java 8
runner which fails with:
...
No matching variant of org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:4.2.1.3168 was found. The consumer was configured to find a library for use during compile-time, compatible with Java 8.
...
> Incompatible because this component declares a component, compatible with Java 11 and the consumer needed a component, compatible with Java 8
This is understandable since the plugin requires Java 11+, running:
./gradlew test
Will return the error shown above.
Running any ./gradlew
command with CI’s job matrix running with JDK 8 will return an error since it can’t resolve sonarqube-gradle-plugin
due to incompatibility.
Is there a way to circumvent this? Or did I just set it up wrong? (most likely)
Things I've tried...
-
Moving sonarqube plugin & configuration in root
build.gradle.kts
-subprojects {}
-
Multiple JDK installation in
setup-java
action, used JDK 11 for building the project first (hopefully getting the dependencies first), then use JDK 8 to test (./gradlew test
)- name: Test with JDK 8 run: | JAVA_HOME=${{ env.JAVA_HOME_11_X64 }} ./gradlew build JAVA_HOME=${{ env.JAVA_HOME_8_X64 }} ./gradlew test --stacktrace
Sample related files:
.github/workflows/test.yml
jobs:
unit:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
java: [ 8, 11, 17, 19 ]
os: [ ... ]
steps:
- uses: actions/checkout@v3
- name: Set up JDK ${{ matrix.java }}
uses: actions/setup-java@v3
with:
java-version: ${{ matrix.java }}
distribution: temurin
- name: Test with JDK ${{ matrix.java }}
run: ./gradlew clean test --stacktrace
build-logic/src/main/kotlin/sonarqube-sample.gradle.kts
plugins {
id("org.sonarqube") // version is defined in version catalog (libs)
...
}
sonarqube {
properties {
val projectKey = "${rootProject.property("GROUP")}:${project.property("ARTIFACT_ID")}"
// project metadata
property("sonar.projectKey", projectKey)
property("sonar.organization", rootProject.property("sonar.organization").toString())
property("sonar.host.url", rootProject.property("sonar.host.url").toString())
property("sonar.projectDescription", project.property("POM_DESCRIPTION").toString())
property("sonar.projectVersion", project.property("VERSION").toString())
// project reports
property(
"sonar.coverage.jacoco.xmlReportPaths",
"${project.projectDir}/build/reports/jacoco/test/jacocoTestReport.xml"
)
property(
"sonar.kotlin.detekt.reportPaths",
"${project.projectDir}/build/reports/detekt/detekt.xml"
)
}
}
...
build-logic/build.gradle.kts
plugins {
`kotlin-dsl`
}
repositories {
gradlePluginPortal()
mavenCentral()
}
dependencies {
...
implementation(libs.sonarqube)
}