JaCoCo and MR Jars

雨燕双飞 提交于 2019-12-14 00:24:05

问题


There is an issue with JaCoCo and the MultiRelease JAR files. Since the same class name exist on two places, JaCoCo complains:

Caused by: java.lang.IllegalStateException: Can't add different class with same name: jodd/core/JavaBridge
        at org.jacoco.core.analysis.CoverageBuilder.visitCoverage(CoverageBuilder.java:107)
        at org.jacoco.core.analysis.Analyzer$1.visitEnd(Analyzer.java:96)

How we can tell JaCoCo (in Gradle) to skip the classes from META-INF path? OR to behave like it should (use correct class and ignoring other versions), depending on JVM version?


回答1:


As explained by @nullpointer, JaCoCo doesn't support Multi-Release JAR Files.

My workaround is to ignore the versions classes. I was not able to ignore just the class by explicitly set its name, it looks like JaCoCo is scanning all of them and then only later applies the filters for exclusion (but maybe I am wrong).

Therefore, the only way to remove versions classes was to exclude all resources - since they are not used anyway. Like this:

task codeCoverage(type: JacocoReport) {
    executionData fileTree("${buildDir}/jacoco/").include("*.exec")

    //sourceSets it.sourceSets.main  <--- REPLACED WITH FOLLOWING LINES!!!
    sourceDirectories = it.sourceSets.main.java
    classDirectories = it.sourceSets.main.output.classesDirs

    reports {
        xml.enabled true
        html.enabled true
    }
}

So I changed this:

sourceSets it.sourceSets.main

to this:

sourceDirectories = it.sourceSets.main.java
classDirectories = it.sourceSets.main.output.classesDirs

The difference here that we explicitly state: sourceSets.main.output.classesDirs which excludes resources.

Source




回答2:


JaCoCo doesn't yet provide support for Java 9 Multi-Release JAR Files.

This seems to be in their plans though as tracked at jacoco/issues#407.



来源:https://stackoverflow.com/questions/47664723/jacoco-and-mr-jars

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!