Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I have a Maven project with Java sources and Scala test sources. I generate code coverage using Jacoco during the verify stage. When I try to run the sonar goal either during the verify phase by adding an execution, or by running mvn verify sonar:sonar , I end up with the test directory being added twice by Sonar:

  [INFO] [11:15:34.756] Test directories:
  [INFO] [11:15:34.756]   /Users/xxx/Documents/workspace/misc/xxx/src/test/scala
  [INFO] [11:15:34.756]   /Users/xxx/Documents/workspace/misc/xxx/src/test/scala/../scala

which results in the analysis failing with the following error:

Failed to execute goal org.codehaus.mojo:sonar-maven-plugin:2.1:sonar (default-cli) on project kv-mapper: Can not execute SonarQube analysis: Unable to read and import the source file : '/Users/xxxx/Documents/workspace/misc/xxx/src/test/scala/../scala/xxx/xxxxx/xxx/xxx/xxxxx/xxxxxx.java' with the charset : 'UTF-8'. Duplicate source for resource

My pom.xml (for Sonar) looks like this.

    <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>sonar-maven-plugin</artifactId>
        <version>${sonar.plugin.version}</version>
        <!-- no default executions -->
        <configuration>
            <sonar.core.codeCoveragePlugin>jacoco</sonar.core.codeCoveragePlugin>
            <sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis>
            <sonar.language>java</sonar.language>
            <sonar.jacoco.itReportPath>
                ${basedir}/target/jacoco.exec
            </sonar.jacoco.itReportPath>
            <sonar.exclusions>
                **/test/*
            </sonar.exclusions>
        </configuration>
    </plugin>

How do I configure Sonar to either:

  • exclude test/scala directory entirely?
  • remove the duplicate directory?
  • That is exactly what I did in the pom.xml (see above) with the sonar.exclusions parameter. Do you have a sample pom I might be able to look at? – Siddhu Sep 27, 2013 at 17:46 You have to set exclusions on test files (not on source code): sonar.tests.exclusions property – David RACODON - QA Consultant Sep 27, 2013 at 21:10

    Thanks for contributing an answer to Stack Overflow!

    • Please be sure to answer the question. Provide details and share your research!

    But avoid

    • Asking for help, clarification, or responding to other answers.
    • Making statements based on opinion; back them up with references or personal experience.

    To learn more, see our tips on writing great answers.