Search code examples
javagradlesonarqubelombokjacoco

Excluding lombok coverage in Sonar does not work


I am trying to exclude Lombok coverage in Sonar.

This is my build.gradle:

plugins {
//...
    id "org.sonarqube" version "4.0.0.2929"
    id 'jacoco'
}

jacocoTestReport {
    reports {
        xml.enabled true
    }
}
test.finalizedBy jacocoTestReport

//...

To exclude those classes I tried the following steps:

  1. I created a lombok.config file in this path: src\main\resources
  2. I added the following properties:
# This tells lombok this directory is the root,
# no need to look somewhere else for java code.
config.stopBubbling = true
# This will add the @lombok.Generated annotation
# to all the code generated by Lombok,
# so it can be excluded from coverage by jacoco.
lombok.addLombokGeneratedAnnotation = true
  1. I added this in build.gradle:
jacocoTestReport {
    // ...
    afterEvaluate {
        classDirectories.setFrom(files(classDirectories.files.collect {
            fileTree(dir: it, exclude: ['lombok/**'])
        }))
    }
}
  1. Cleaning the project before executing the sonar task:
gradlew.bat clean build test --debug sonar -Dsonar.projectKey=" + service + " -Dsonar.projectName=" + service + " -Dsonar.host.url=http://localhost:9000 -Dsonar.token=" + global_token

Unfortunately for some reason after executing the sonar task to analyze the project,

I still have the Lombok code uncovered:

uncovered code


Solution

  • lombok.config must be in the root of the project, not in src\main\resources