Skip to content

Commit

Permalink
[CI] SonarCloud integration
Browse files Browse the repository at this point in the history
  • Loading branch information
odoralc committed Dec 5, 2022
1 parent 3c1804c commit e015bdd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 50 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/maven.yml
Expand Up @@ -39,7 +39,7 @@ jobs:
uses: gradle/gradle-build-action@v2
with:
gradle-version: 7.3
arguments: clean test codeCoverageReport --info --continue
arguments: clean test --info --continue

- name: Set up JDK 11
uses: actions/setup-java@v2
Expand Down
60 changes: 11 additions & 49 deletions build.gradle
Expand Up @@ -17,10 +17,16 @@ sonarqube {
property "sonar.sourceEncoding", "UTF-8"
property "sonar.host.url", "https://sonarcloud.io"
property "sonar.java.source", "8"
property 'sonar.coverage.jacoco.xmlReportPaths', "$projectDir.parentFile.path/build/reports/jacoco/codeCoverageReport/codeCoverageReport.xml"
property 'sonar.jacoco.reportPaths', allTestCoverageFile
}
}

def allTestCoverageFile = "${rootProject.buildDir}/jacoco/allTestCoverage.exec"
task jacocoMerge(type: JacocoMerge, group: 'verification') {
destinationFile = file(allTestCoverageFile)
executionData = project.fileTree(dir: '.', include:'**/build/jacoco/test.exec')
}

subprojects {

apply plugin: 'java'
Expand All @@ -47,7 +53,7 @@ subprojects {
property "sonar.sourceEncoding", "UTF-8"
property "sonar.host.url", "https://sonarcloud.io"
property "sonar.java.source", "8"
property 'sonar.coverage.jacoco.xmlReportPaths', "$projectDir.parentFile.path/build/reports/jacoco/codeCoverageReport/codeCoverageReport.xml"
property 'sonar.jacoco.reportPaths', allTestCoverageFile
}
}

Expand All @@ -57,53 +63,9 @@ subprojects {
}

jacoco {
toolVersion = "0.8.0"
toolVersion = "0.8.3"
}
}

// See here for more info: https://docs.gradle.org/6.4-rc-1/samples/sample_jvm_multi_project_with_code_coverage.html
//
// tag::coverageTask[]
// task to gather code coverage from multiple subprojects
// NOTE: the `JacocoReport` tasks do *not* depend on the `test` task by default. Meaning you have to ensure
// that `test` (or other tasks generating code coverage) run before generating the report.
// You can achieve this by calling the `test` lifecycle task manually
// $ ./gradlew test codeCoverageReport
tasks.register("codeCoverageReport", JacocoReport) {
// If a subproject applies the 'jacoco' plugin, add the result it to the report
subprojects { subproject ->
subproject.plugins.withType(JacocoPlugin).configureEach {
subproject.tasks.matching({ t -> t.extensions.findByType(JacocoTaskExtension) }).configureEach { testTask ->
if (subproject.buildFile.exists()) {
//the jacoco extension may be disabled for some projects
if (testTask.extensions.getByType(JacocoTaskExtension).isEnabled()) {
sourceSets subproject.sourceSets.main
executionData(testTask)
} else {
logger.warn('Jacoco extension is disabled for test task \'{}\' in project \'{}\'. this test task will be excluded from jacoco report.', testTask.getName(), subproject.getName())
}
}
}
test.finalizedBy(jacocoMerge)

// To automatically run `test` every time `./gradlew codeCoverageReport` is called,
// you may want to set up a task dependency between them as shown below.
// Note that this requires the `test` tasks to be resolved eagerly (see `forEach`) which
// may have a negative effect on the configuration time of your build.
subproject.tasks.matching({ t -> t.extensions.findByType(JacocoTaskExtension) }).forEach {
rootProject.tasks.codeCoverageReport.dependsOn(it)
}
}
}

// enable the different report types (html, xml, csv)
reports {
// xml is usually used to integrate code coverage with
// other tools like SonarQube, Coveralls or Codecov
xml.enabled true

// HTML reports can be used to see code coverage
// without any external tools
html.enabled true
}
}
// end::coverageTask[]
}

0 comments on commit e015bdd

Please sign in to comment.