如何在运行“maven clean install”时仅运行一次单元测试和声纳?

发布于 2024-12-05 10:13:12 字数 408 浏览 1 评论 0原文

我的 Jenkins 工作有以下配置: 首先清理并构建 Maven 项目,然后运行单元测试和静态分析:clean install sonar:sonar 问题是 installsonar:sonar 各自运行单元测试,这实际上使构建时间增加了一倍。

我通过将 clean install sonar:sonar 更改为 clean install -DskipTests 并使用 Jenkins 声纳插件运行 Sonar 来修复此问题。现在单元测试只运行一次,声纳显示结果,但詹金斯不再知道测试了。

我的猜测是,Jenkins 仅在构建后查看 Surefire-reports 文件夹,而不是在 Sonar(这是构建后操作)之后查看。

I had the following configuration for my Jenkins job:
First clean and build the maven project, then run the unit tests and static analysis: clean install sonar:sonar
The problem was that install and sonar:sonar each ran the unit tests which effectively doubled the build time.

I fixed this by changing clean install sonar:sonar to clean install -DskipTests and running Sonar using the Jenkins sonar plugin. Now the unit tests ran only once and sonar showed the results, but Jenkins didn't know about the tests anymore.

My guess is that Jenkins is only looking at the surefire-reports folder after building, not after Sonar (which is a post-build action).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

桃酥萝莉 2024-12-12 10:13:12

您可以先运行 clean install -DskipTests,然后添加第二个 Maven 构建步骤 sonar:sonar
测试(以及完整的声纳分析)将在构建阶段运行,之后詹金斯可以收集可靠的结果。

You could just run clean install -DskipTests first and then add a second maven build step sonar:sonar.
The tests (and complete sonar analysis) will be run during the build phase, and the surefire results can be collected by jenkins afterwards.

不气馁 2024-12-12 10:13:12

正如您所说,Sonar 是编译后步骤。 Sonar 要求构建完成并通过所有测试才能运行,否则它所做的事情没有任何意义。

声纳使用仪器运行测试(如果我没记错的话,cobertura),它给出了测试的代码覆盖率。

因此,您需要在 Sonar 运行之前安装(或至少编译和测试),然后 Sonar 出于其自身目的使用仪器重新运行测试。

As you said, Sonar is a post compile step. Sonar requires that the build be complete and pass all of it's tests before it can run, otherwise the things it does don't make any sense.

Sonar runs the tests with instrumenting (cobertura if I remember correctly), which gives the code coverage for the tests.

So, you need to do install (or at least compile & test) before Sonar runs, and then Sonar reruns the tests with instrumenting for it's own purposes.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文