Sonar Maven 插件:如何排除测试源目录? [英] Sonar Maven Plugin: How do I exclude test source directories?
问题描述
我有一个包含 Java 源和 Scala 测试源的 Maven 项目.我在 verify
阶段使用 Jacoco
生成代码覆盖率.当我尝试在验证阶段通过添加执行或运行 mvn verify sonar:sonar
来运行声纳目标时,我最终会发现测试目录被 Sonar 添加了两次:
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
我的 pom.xml(用于声纳)看起来像这样.
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>
如何将 Sonar 配置为:
How do I configure Sonar to either:
- 完全排除 test/scala 目录?或
- 删除重复的目录?
推荐答案
在运行 SonarQube 分析之前添加一个删除文件夹的步骤.或者对测试文件设置排除项.请参阅 http://docs.sonarqube.org/display/SONAR/缩小+the+Focus#NarrowingtheFocus-IgnoreFiles
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
这篇关于Sonar Maven 插件:如何排除测试源目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!