3

我在哈德逊有一堆 Maven 项目,Sonar 坐在旁边。Sonar 为我提供了 Sonar 统计信息、FindBugs 统计信息和代码覆盖率。

我注意到,无论我是使用 Sonar 还是直接通过 Maven 使用 EMMA,整个构建周期都会运行两次。这包括 init (在我的例子中,它重新初始化数据库 - 昂贵)和单元测试(几百 - 也很昂贵)。

我怎样才能防止这种情况?我做了很多阅读,这似乎是由于代码覆盖插件的设计 - 将未检测的类与检测的类分开。

我尝试过如下配置:

  • Maven 运行:部署、EMMA
  • Maven 运行:部署;完成后部署到声纳
4

2 回答 2

1

The sonar documentation recommends running the sonar plugin in 2 stages:-

mvn clean install -Dtest=false -DfailIfNoTests=false

mvn sonar:sonar

The tests are bypassed in the first phase and run implicitly in the second stage.

A one line alternative is to run the following command:-

mvn clean install sonar:sonar -Dmaven.test.failure.ignore=true

but this will run the tests twice - as you have found.

于 2011-03-16T22:23:20.857 回答
1

要添加到@Strawberry 的答案,您可以重用单元测试报告而不是再次运行它们。请参阅声纳文档中的重用现有单元测试报告部分

完成后,您可以在 Hudson 中配置以下内容

clean deploy sonar:sonar
于 2011-03-17T04:26:52.833 回答