如何避免使用 cobertura:check 进行双重编译和测试?
我正在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
有几个与此相关的问题(请参阅 MCOBERTURA-83、MCOBERTURA-76)但是据我所知,没有完美的解决方法(由于生命周期的构建方式 - 事物) Maven 3 中可能会得到改进)。
我知道的唯一一个(与 CI 服务器一起使用)是运行:
然后
而不是在构建生命周期上绑定
cobertura:check
。请注意,编译两次不应该成为问题,因为所有类都应该是最新的。
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:
and then
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.
据我所知,cobertura 需要对您的代码进行字节码编织才能工作。
As far as I know, cobertura needs to do bytecode weaving on your code to be able to work.
我能够解决这个问题的唯一方法是将字节码作为我的构建的一部分进行检测(通过将 cobertura:instrument 目标绑定到 verify 阶段并绑定从
maven-surefire-plugin
到verify
阶段的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 theverify
phase and also bind thedefault-test
execution frommaven-surefire-plugin
to theverify
phase so it doesn't get executed as part of thetest
phase on everycobertura
goal execution.