Exclude package from Jacoco coverage in Jenkins

别来无恙 提交于 2019-12-13 06:30:55

问题


Trying to exclude packages from coverage report as my Jenkins pipeline fail. I have a sub project with all POJO:s. I don't want to write uittest for all these. Hence, they will drag down branch/line coverage som that coverage will be below threshold and fail my build.

It should be possible to exclude some packages, but I cant get it to work.

I have the following jacoco.gradle file:

apply plugin: 'jacoco'  
apply plugin: 'java'  
jacoco {  
  toolVersion = "0.8.2"  
}  

jacocoTestReport {  
reports {  
  xml.enabled true  
  csv.enabled false  
  html.enabled true  
}  

afterEvaluate {  
  classDirectories = files(classDirectories.files.collect {  
     fileTree(dir: it, exclude: '**xxx/yyy/zzz/**')  
  })  
}  

task coverage { dependsOn 'jacocoTestReport' }  

check.dependsOn 'jacocoTestReport'  

The following in my sonar.gradle file:

apply plugin: 'org.sonarqube'  

sonarqube {  
properties {  
  property "sonar.forceAnalysis", "true"  
  property "sonar.forceAuthentication", "true"  
  property "sonar.java.coveragePlugin", "jacoco"  
  property "sonar.login", ""  
  property "sonar.password", ""  
 }  
}  

subprojects {  
 sonarqube {  
  properties {  
     property "sonar.jacoco.reportPaths", 
 "$buildDir/reports/jacoco/allTests.exec"
     property "sonar.junit.reportsPath", "$buildDir/test-results/test"  
  }  
 }  
}  

task sonar { dependsOn 'sonarqube' }  

In my build.gradle:

apply from: 'gradle/sonar.gradle'  
...  
apply plugin: 'java'  
...  
subprojects {  
  apply from: '../gradle/jacoco.gradle'   
  ...  
}  

And finally from my Jenkins file:

step([$class: 'JacocoPublisher', changeBuildStatus: false, 
 exclusionPattern: '**/*Test*.class', inclusionPattern: 
 '**/*.class', minimumBranchCoverage: '80', sourcePattern: '**/src'])  

try {  
 dir(BUILD_DIR) {  
 sh './gradlew sonar'  
}  

But still the xxx.yyy.zzz Is generated in the coverage report in Jenkins!


回答1:


Finally got it working! The key is the JacocoPuplisher.

step([$class: 'JacocoPublisher', changeBuildStatus: false, exclusionPattern: 
'**/xxx/yyy/zzz/**/*.class, **/*Test*.class', inclusionPattern: '**/*.class', 
minimumBranchCoverage: '80', sourcePattern: '**/src'])

This is the only way to I get it to work with Jenkins.

Setting the sonar.coverage.exclusion or using the afterEvalueate stuff above has no effect.



来源:https://stackoverflow.com/questions/53883900/exclude-package-from-jacoco-coverage-in-jenkins

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!