类路径上的 asm 的 cobertura 问题
我有一个使用 maven、Spring 2.5.6、Hibernate 3.2.6 的项目设置,最近添加了 cobertura 1.9rc1 进行代码覆盖率分析。
我遇到的第一个问题是与类路径相关的错误,因为类路径上有两个不同版本的 asm.jar。仅当运行 JUnit 测试并尝试加载 spring 应用程序上下文时,此问题才会出现。
根据 cobertura 项目主页上的常见问题解答:
为什么 Cobertura 导致我与 ASM 发生类路径冲突?
Cobertura 使用 ASM 来修改您的字节码。还有一些其他流行的程序也使用 ASM;仅举两个例子,Groovy 和 Hibernate。如果 Cobertura 使用不同版本的 asm 并且将这两个版本添加到类路径中,则可能会出现问题。
Cobertura 在检测时仅使用 ASM。运行测试时,Cobertura 在类路径中不需要 ASM。如果您发现类路径冲突,只需确保 Cobertura 附带的 asm jar 仅由 Cobertura 使用,并且仅在检测时使用。
因此,在我的项目 pom 中,我配置了依赖项,如下所示:
<dependency>
<groupId>net.sourceforge.cobertura</groupId>
<artifactId>cobertura</artifactId>
<version>1.9rc1</version>
<exclusions>
<exclusion>
<groupId>asm</groupId>
<artifactId>asm</artifactId>
</exclusion>
<exclusion>
<groupId>asm</groupId>
<artifactId>asm-attrs</artifactId>
</exclusion>
</exclusions>
</dependency>
现在我可以从 eclipse 运行我的单元测试,我的应用程序也在服务器上运行良好。
但是,当我在项目上运行 mvn cobertura:cobertura 时,出现以下错误: java.lang.NoClassDefFoundError: net/sourceforge/cobertura/coveragedata/TouchCollector
我认为这是因为错误的 asm.jar 位于类路径上。但是,正如 cobertura 常见问题解答中所述,我还能如何解决这个类路径冲突呢?
I've got a project setup using maven, Spring 2.5.6, Hibernate 3.2.6 and recently added cobertura 1.9rc1 for code coverage analysis.
The first issue I ran into were classpath related errors because of two different versions of the asm.jar on the classpath. This issue would only rise when running the JUnit tests and trying to load the spring application context.
According to the FAQ on cobertura project homepage:
Why is Cobertura causing me to have classpath conflicts with ASM?
Cobertura uses ASM to modify your bytecode. There are a few other popular programs that use ASM; Groovy and Hibernate, to name two. You could have problems if Cobertura uses a different version of asm and you add both versions to your classpath.
Cobertura only uses ASM when instrumenting. Cobertura does not need ASM in your classpath when running tests. If you're seeing classpath conflicts, just make sure the asm jar that comes with Cobertura is used only by Cobertura, and only when instrumenting.
So in my project pom I configured the dependency as follows:
<dependency>
<groupId>net.sourceforge.cobertura</groupId>
<artifactId>cobertura</artifactId>
<version>1.9rc1</version>
<exclusions>
<exclusion>
<groupId>asm</groupId>
<artifactId>asm</artifactId>
</exclusion>
<exclusion>
<groupId>asm</groupId>
<artifactId>asm-attrs</artifactId>
</exclusion>
</exclusions>
</dependency>
Now I can run my unit tests from eclipse, my application also runs fine on the server.
But, when I run mvn cobertura:cobertura on my project I get the following error:
java.lang.NoClassDefFoundError: net/sourceforge/cobertura/coveragedata/TouchCollector
I assume this is because the wrong asm.jar is on the classpath. But how else can I solve this classpath conflict, as stated in the cobertura faq?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要配置 maven-cobertura-plugin,您应该将其添加到
部分,而不是作为
- 我假设您的项目代码没有需要 cobertura 来编译。运行
mvn cobertura:cobertura
时,您引用的
部分将根本不会被引用。例如:
To configure the maven-cobertura-plugin, you should add it in the
<plugins>
section, not as a<dependency>
- I assume your project code does not need cobertura to compile.When running
mvn cobertura:cobertura
the<dependency>
section you quoted will not be referred to at all.For example: