我已經使用maven,Spring 2.5.6,Hibernate 3.2.6和最近添加的cobertura 1.9rc1進行了代碼覆蓋率分析。在類路徑上使用asm的cobertura問題
我碰到的第一個問題是classpath相關的錯誤,因爲classpath上有兩個不同版本的asm.jar。這個問題只會在運行JUnit測試並嘗試加載Spring應用程序上下文時纔會上升。
據對的Cobertura項目主頁上的常見問題解答:
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.
所以,在我的項目的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:網/ sourceforge上/的Cobertura/coveragedata/TouchCollector
我想這是因爲錯誤的asm.jar在類路徑中。但是我怎麼能解決這個類路徑衝突,正如cobertura faq所述?
好的建議應該已被標記爲答案。 – 2013-04-18 16:00:57