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(用于Sonar)看起来像这样.
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目录吗? 或
- 要删除重复目录吗?
- exclude test/scala directory entirely? or
- remove the duplicate directory?
推荐答案
在运行SonarQube分析之前,要么添加步骤以删除文件夹. 或在测试文件上设置排除项.请参见 http://docs.sonarqube.org/display/SONAR/Narrowing + 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屋!