title: Filter JaCoCo coverage reports with Gradle
body: <h1>Problem:</h1>
  <p>I have a project with <a href="/questions/tagged/jacoco" class="post-tag" title="show questions tagged &#39;jacoco&#39;" rel="tag">jacoco</a> and I want to be able to filter certain classes and/or packages.</p>
  <h1>Related Documentation:</h1>
  <p>I have read the following documentation:</p>
  <p><strong>Official <a href="/questions/tagged/jacoco" class="post-tag" title="show questions tagged &#39;jacoco&#39;" rel="tag">jacoco</a> site:</strong>
  <a href="http://www.eclemma.org/jacoco/index.html" rel="noreferrer">http://www.eclemma.org/jacoco/index.html</a></p>
  <p><strong>Official <a href="/questions/tagged/jacoco" class="post-tag" title="show questions tagged &#39;jacoco&#39;" rel="tag">jacoco</a> docs for <a href="/questions/tagged/gradle" class="post-tag" title="show questions tagged &#39;gradle&#39;" rel="tag">gradle</a>:</strong> <a href="https://gradle.org/docs/current/userguide/jacoco_plugin.html" rel="noreferrer">https://gradle.org/docs/current/userguide/jacoco_plugin.html</a></p>
  <p><strong>Official <a href="/questions/tagged/jacoco" class="post-tag" title="show questions tagged &#39;jacoco&#39;" rel="tag">jacoco</a> <code>Github</code> issues, working on coverage:</strong>
  <a href="https://github.com/jacoco/jacoco/wiki/FilteringOptions" rel="noreferrer">https://github.com/jacoco/jacoco/wiki/FilteringOptions</a>
  <a href="https://github.com/jacoco/jacoco/issues/14" rel="noreferrer">https://github.com/jacoco/jacoco/issues/14</a></p>
  <h1>Related StackOverflow Links:</h1>
  <p><a href="https://stackoverflow.com/questions/19625640/jacoco-gradle-filtering-options">JaCoCo &amp; Gradle - Filtering Options</a> (No answer)</p>
  <p><a href="https://stackoverflow.com/questions/27033757/exclude-packages-from-jacoco-report-using-sonarrunner-and-gradle">Exclude packages from Jacoco report using Sonarrunner and Gradle</a> (Not using <a href="/questions/tagged/sonar" class="post-tag" title="show questions tagged &#39;sonar&#39;" rel="tag">sonar</a>)</p>
  <p><a href="https://stackoverflow.com/questions/14682389/jacoco-exclude-jsp-from-report">JaCoCo - exclude JSP from report</a> (It seems to work for <a href="/questions/tagged/maven" class="post-tag" title="show questions tagged &#39;maven&#39;" rel="tag">maven</a>, I am using <a href="/questions/tagged/gradle" class="post-tag" title="show questions tagged &#39;gradle&#39;" rel="tag">gradle</a>)</p>
  <p><a href="https://stackoverflow.com/questions/27799419/maven-jacoco-configuration-exclude-classes-packages-from-report-not-working">Maven Jacoco Configuration - Exclude classes/packages from report not working</a> (It seems to work for <a href="/questions/tagged/maven" class="post-tag" title="show questions tagged &#39;maven&#39;" rel="tag">maven</a>, I am using <a href="/questions/tagged/gradle" class="post-tag" title="show questions tagged &#39;gradle&#39;" rel="tag">gradle</a>)</p>
  <p><a href="https://stackoverflow.com/questions/23756014/jacoco-gradle-plugin-exclude">JaCoCo gradle plugin exclude</a> (Could not get this to work)</p>
  <p><a href="https://stackoverflow.com/questions/17394427/gradle-jacoco-coverage-reports-includes-classes-excluded-in-configuration">Gradle Jacoco - coverage reports includes classes excluded in configuration</a> (Seems very close, it used <code>doFirst</code>, did not work for me)</p>
  <h1>Example of what I have tried:</h1>
  <pre><code>apply plugin: 'java'
  apply plugin: 'jacoco'
  
  buildscript {
      repositories {
          mavenCentral()
          jcenter()
      }
  }
  
  repositories {
      jcenter()
  }
  
  jacocoTestReport {
      reports {
          xml {
              enabled true // coveralls plugin depends on xml format report
          }
  
          html {
              enabled true
          }
      }
  
      test {
          jacoco {
              destinationFile = file(&quot;$buildDir/jacoco/jacocoTest.exec&quot;)
              classDumpFile = file(&quot;$buildDir/jacoco/classpathdumps&quot;)
              excludes = [&quot;projecteuler/**&quot;] // &lt;-- does not work
              // excludes = [&quot;projecteuler&quot;]
          }
      }
  }
  </code></pre>
  <h1>Question:</h1>
  <p><strong>How can I exclude certain packages and classes when generating the <a href="/questions/tagged/jacoco" class="post-tag" title="show questions tagged &#39;jacoco&#39;" rel="tag">jacoco</a> coverage reports?</strong></p>