如何避免使用 cobertura:check 进行双重编译和测试?

发布于 2024-09-13 00:01:38 字数 238 浏览 10 评论 0原文

我正在使用 maven-cobertura-plugin 来计算项目中的代码覆盖率。据我了解,该插件启动一个新的/分叉的构建周期,以便编译和测试代码库。完成后,插件会计算代码覆盖率。据我了解,这是该插件可以使用的唯一方法,而且对我来说很好。

问题是在 cobertura 插件之前我的代码库已经编译和测试过。因此,我正在经历重复的编译和测试。是否可以在 cobertura 之前避免编译和测试?或者也许还有其他解决方法?

I'm using maven-cobertura-plugin in order to calculate code coverage in my project. As I understand, this plugin starts a new/forked build cycle in order to compile and test the code base. When it's done the plugin calculates code coverage. As I understand, this is the only approach the plugin can use, and it's fine for me.

The problem is that before cobertura plugin my code base is compiled and tested already. Thus, I'm experiencing duplicated compilation and testing. Is it possible to avoid compilation and testing before cobertura? Or maybe there is some other workaround?

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

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

发布评论

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

评论(3

不乱于心 2024-09-20 00:01:38

是否可以在cobertura之前避免编译和测试?或者也许还有其他解决方法?

有几个与此相关的问题(请参阅 MCOBERTURA-83MCOBERTURA-76)但是据我所知,没有完美的解决方法(由于生命周期的构建方式 - 事物) Maven 3 中可能会得到改进)。

我知道的唯一一个(与 CI 服务器一起使用)是运行:

mvn clean install -Dmaven.test.skip=true

然后

mvn cobertura:check

而不是在构建生命周期上绑定 cobertura:check

请注意,编译两次不应该成为问题,因为所有类都应该是最新的。

Is it possible to avoid compilation and testing before cobertura? Or maybe there is some other workaround?

There are several issues about this (see MCOBERTURA-83, MCOBERTURA-76) but AFAIK, there is no perfect workaround (due to the way the life cycle is constructed - things might be improved in Maven 3).

The only one I'm aware of (works with CI servers) would be to run:

mvn clean install -Dmaven.test.skip=true

and then

mvn cobertura:check

Instead of binding cobertura:check on the build lifecycle.

Note that compiling twice shouldn't be an issue as all classes should be up to date.

寄居者 2024-09-20 00:01:38

据我所知,cobertura 需要对您的代码进行字节码编织才能工作。

As far as I know, cobertura needs to do bytecode weaving on your code to be able to work.

久夏青 2024-09-20 00:01:38

我能够解决这个问题的唯一方法是将字节码作为我的构建的一部分进行检测(通过将 cobertura:instrument 目标绑定到 verify 阶段并绑定从 maven-surefire-pluginverify 阶段的 default-test 执行,因此它不会作为 的一部分执行每个 cobertura 目标执行的测试阶段。

The only way I was able to work around that was to instrument the byte code as part of my build (by binding the cobertura:instrument goal to the verify phase and also bind the default-test execution from maven-surefire-plugin to the verify phase so it doesn't get executed as part of the test phase on every cobertura goal execution.

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