我有一个带有Java源代码和Scala测试源的Maven项目.我Jacoco在verify舞台上使用代码覆盖.当我尝试在验证阶段通过添加执行或运行来运行声纳目标时mvn verify sonar:sonar,我最终将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
Run Code Online (Sandbox Code Playgroud)
这导致分析失败,出现以下错误:
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
Run Code Online (Sandbox Code Playgroud)
我的pom.xml(对于Sonar)看起来像这样.
<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>
Run Code Online (Sandbox Code Playgroud)
如何将Sonar配置为:
我在JAVA有一个项目,我用声纳分析.我拥有的一些java包都在源文件夹下.我也有一些测试文件,我在不同的文件夹下.现在,在Sonar中,我以不同的结构组织我的项目,即对于项目"搜索",我只想包括"搜索"包.使用sonar.exclusion属性很容易实现这些排除.不过,我的问题是测试怎么样?我怎样才能排除一些包?因为在我的测试中,即使我的源和测试文件夹使用相同的结构,当我指定"sonar.exclusions"时,测试包也不会自动排除.
我的文件夹结构:
/src/com/domain/
-- search/
-- utils/
-- pooling/
-- category/
/test/src/com/domain/
-- utils/
-- pooling/
Run Code Online (Sandbox Code Playgroud)
声纳属性:
<property name="sonar.sources" value="${path}/src" />
<property name="sonar.tests" value="${path}/test/src" />
<property name="sonar.exclusions" value="com/domain/utils/**/*,com/domain/pooling/**/*,com/domain/category/**/*" />
Run Code Online (Sandbox Code Playgroud)
所以,我试图只包括"搜索"包.上面的代码工作方式使得SONAR只分析我的"搜索"包.可以在SONAR"组件"选项卡中看到此包.不幸的是,除了"搜索"组件,我还可以看到"util"和"pooling"组件.我做了一些测试,并确定这两个组件(utils和pooling)是"sonar.tests"属性的结果.只是注意,尽管"util"和"pooling"显示在组件中,但SONAR在它们下面显示零文件.所以回到我的问题,无论如何,我可以做到排除"util"和"汇集"在"组件"下显示?也许使用属性(即声纳测试排除)?
顺便说一句,我正在使用SONAR 2.11并在Red Hat linux下运行.我正在使用SONAR-TASK 1.2.
任何帮助都受到欢迎和赞赏!谢谢!