Domanda

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? or
  • remove the duplicate directory?
È stato utile?

Soluzione 2

Either add a step to remove the folder before running the SonarQube analysis. Or set exclusions on test files. See http://docs.sonarqube.org/display/SONAR/Narrowing+the+Focus#NarrowingtheFocus-IgnoreFiles

Altri suggerimenti

sonar.test.exclusions should be used instead of sonar.exclusions

<sonar.test.exclusions>
   **/test/*
</sonar.test.exclusions>
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top