简体   繁体   中英

sonar package exclusion to increase code coverage

tool:SonarQube Scanner 3.2

I wish to exclude some packages from sonar code Coverage where sonar is part of build pipeline of jenkins.

Ways tried (for now added all files under the package mentioned just to check if it really excludes all java file !) pom.xml

  1. <sonar.coverage.exclusions>com/**/</sonar.coverage.exclusions>

  2. <sonar.exclusions>{project.basedir}/src/main/java/com/ept/scheduleinterface/dto/**/*, {project/basedir}/src/main/java/com/test/aa//model/</sonar.exclusions>

jenkinsfile

  1. sonar: [projectKey: PROJECT_NAME, 'java.libraries':'/root/.m2/repository/org/projectlombok/lombok//lombok-.jar','sonar.coverage.exclusions': 'src/main/java/com//'**],

  2. '-Dsonar.coverage.exclusions': 'src/main/java/com//']**

  3. '-Dsonar.coverage.exclusions': 'com//*']**,

In my project structure there is a jenkinsfile and pom.xml file along with dockerfile.

But it looks is sonar is not obeying the configuration at all. Also I can see in jenkins console logs the changes I did in eg jenkins file are considered

Running shell script:

‘-Dsonar.java.libraries=/root/.m2/repository/org/projectlombok/lombok//lombok-.jar’ ‘-Dsonar.sonar.coverage.exclusions=src/main/java/com/**/*’ -Dsonar.sources=src -Dsonar.java.binaries=target/classes -Dsonar.jacoco.reportPaths=target/jacoco.exec -

屏幕截图

you need to put something like below (put both theses properties in your gradle file)

sonarqube {
properties {


    /**
     * For detailed meaning of the following exclusion properties, please checkout:
     * https://docs.sonarqube.org/display/SONAR/Analysis+Parameters
     */
    property "sonar.coverage.exclusions", "**/generated/**/*.java,**/generated-src/**/*.java"
    property "sonar.exclusions", "**/generated/**/*.java,**/generated-src/**/*.java"
}
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM