title: Exclude package from Jacoco coverage in Jenkins
body: <p>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.</p>
  
  <p>It should be possible to exclude some packages, but I cant get it to work.</p>
  
  <p>I have the following jacoco.gradle file:  </p>
  
  <pre><code>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'  
  </code></pre>
  
  <hr>
  
  <p>The following in my sonar.gradle file:  </p>
  
  <pre><code>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' }  
  </code></pre>
  
  <hr>
  
  <p>In my build.gradle:  </p>
  
  <pre><code>apply from: 'gradle/sonar.gradle'  
  ...  
  apply plugin: 'java'  
  ...  
  subprojects {  
    apply from: '../gradle/jacoco.gradle'   
    ...  
  }  
  </code></pre>
  
  <hr>
  
  <p>And finally from my Jenkins file:  </p>
  
  <pre><code>step([$class: 'JacocoPublisher', changeBuildStatus: false, 
   exclusionPattern: '**/*Test*.class', inclusionPattern: 
   '**/*.class', minimumBranchCoverage: '80', sourcePattern: '**/src'])  
  
  try {  
   dir(BUILD_DIR) {  
   sh './gradlew sonar'  
  }  
  </code></pre>
  
  <hr>
  
  <p>But still the xxx.yyy.zzz Is generated in the coverage report in Jenkins!</p>