title: SonarQube - Java - Sonar Scanner not analyzing src/test/java folders
body: <p>I downloaded SonarQube 7.0, and setup the Maven project to use Sonar scanner. The pom.xml looks like the following:</p>
  
  <pre><code>&lt;project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
       xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"&gt;
  &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  
  &lt;groupId&gt;com.github.jitpack&lt;/groupId&gt;
  &lt;artifactId&gt;maven-simple&lt;/artifactId&gt;
  &lt;version&gt;0.2-SNAPSHOT&lt;/version&gt;
  &lt;packaging&gt;jar&lt;/packaging&gt;
  
  &lt;name&gt;Simple Maven example&lt;/name&gt;
  &lt;url&gt;https://jitpack.io/#jitpack/maven-simple/0.1&lt;/url&gt;
  
  &lt;properties&gt;
      &lt;maven.compiler.source&gt;1.8&lt;/maven.compiler.source&gt;
      &lt;maven.compiler.target&gt;1.8&lt;/maven.compiler.target&gt;
      &lt;mavenSurefireVersion&gt;2.20&lt;/mavenSurefireVersion&gt;
      &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
      &lt;src.dir&gt;src/main/java&lt;/src.dir&gt;
      &lt;sonar.sources&gt;pom.xml,src/main/java&lt;/sonar.sources&gt;
      &lt;mavenSurefireVersion&gt;2.20&lt;/mavenSurefireVersion&gt;
  &lt;/properties&gt;
  
  &lt;dependencies&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.testng&lt;/groupId&gt;
          &lt;artifactId&gt;testng&lt;/artifactId&gt;
          &lt;version&gt;6.8&lt;/version&gt;
          &lt;scope&gt;test&lt;/scope&gt;
      &lt;/dependency&gt;
  &lt;/dependencies&gt;
  
  &lt;profiles&gt;
      &lt;profile&gt;
          &lt;id&gt;sonarLocal&lt;/id&gt;
          &lt;activation&gt;
              &lt;activeByDefault&gt;false&lt;/activeByDefault&gt;
          &lt;/activation&gt;
          &lt;properties&gt;
              &lt;sonar.host.url&gt;http://localhost:9000&lt;/sonar.host.url&gt;
          &lt;/properties&gt;
      &lt;/profile&gt;
  &lt;/profiles&gt;
  
  &lt;build&gt;
      &lt;sourceDirectory&gt;${src.dir}&lt;/sourceDirectory&gt;
      &lt;testResources&gt;
          &lt;testResource&gt;
              &lt;directory&gt;${project.basedir}&lt;/directory&gt;
              &lt;filtering&gt;true&lt;/filtering&gt;
          &lt;/testResource&gt;
      &lt;/testResources&gt;
      &lt;plugins&gt;
          &lt;plugin&gt;
              &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
              &lt;version&gt;3.3&lt;/version&gt;
              &lt;configuration&gt;
                  &lt;source&gt;${maven.compiler.source}&lt;/source&gt;
                  &lt;target&gt;${maven.compiler.source}&lt;/target&gt;
                  &lt;encoding&gt;${project.build.sourceEncoding}&lt;/encoding&gt;
              &lt;/configuration&gt;
          &lt;/plugin&gt;
          &lt;plugin&gt;
              &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
              &lt;artifactId&gt;maven-resources-plugin&lt;/artifactId&gt;
              &lt;version&gt;3.0.2&lt;/version&gt;
              &lt;configuration&gt;
                  &lt;encoding&gt;${project.build.sourceEncoding}&lt;/encoding&gt;
              &lt;/configuration&gt;
          &lt;/plugin&gt;
          &lt;plugin&gt;
              &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
              &lt;artifactId&gt;maven-checkstyle-plugin&lt;/artifactId&gt;
              &lt;version&gt;3.0.0&lt;/version&gt;
              &lt;executions&gt;
                  &lt;execution&gt;
                      &lt;id&gt;validate&lt;/id&gt;
                      &lt;phase&gt;validate&lt;/phase&gt;
                      &lt;configuration&gt;
                          &lt;includeTestSourceDirectory&gt;true&lt;/includeTestSourceDirectory&gt;
                          &lt;configLocation&gt;google_checks.xml&lt;/configLocation&gt;
                          &lt;encoding&gt;${project.build.sourceEncoding}&lt;/encoding&gt;
                          &lt;consoleOutput&gt;true&lt;/consoleOutput&gt;
                          &lt;failsOnError&gt;true&lt;/failsOnError&gt;
                          &lt;failOnViolation&gt;true&lt;/failOnViolation&gt;
                          &lt;violationSeverity&gt;warning&lt;/violationSeverity&gt;
                      &lt;/configuration&gt;
                      &lt;goals&gt;
                          &lt;goal&gt;check&lt;/goal&gt;
                      &lt;/goals&gt;
                  &lt;/execution&gt;
              &lt;/executions&gt;
          &lt;/plugin&gt;
          &lt;plugin&gt;
              &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
              &lt;artifactId&gt;maven-surefire-plugin&lt;/artifactId&gt;
              &lt;version&gt;${mavenSurefireVersion}&lt;/version&gt;
          &lt;/plugin&gt;
          &lt;plugin&gt;
              &lt;groupId&gt;org.sonarsource.scanner.maven&lt;/groupId&gt;
              &lt;artifactId&gt;sonar-maven-plugin&lt;/artifactId&gt;
              &lt;version&gt;3.4.0.905&lt;/version&gt;
          &lt;/plugin&gt;
      &lt;/plugins&gt;
  &lt;/build&gt;
  </code></pre>
  
  <p></p>
  
  <p>My structure of the project looks like below:</p>
  
  <p>src/main/java --> Contains app code.</p>
  
  <p>src/test/java --> Contains all test code.</p>
  
  <p>I use the command, "mvn clean install sonar:sonar -PsonarLocal" to execute Sonar.</p>
  
  <p>Now I observed that Sonar never analyzes all .java files in the src/test/java folder. </p>
  
  <p>To prove this, I added an unused variable in one of the test classes, and Sonar didn't catch it. If I do the same thing in any file in the src/main/java folder, Sonar catches it.</p>
  
  <p>Is there something I'm missing?</p>