JaCoCo和MR Jars [英] JaCoCo and MR Jars

查看:121
本文介绍了JaCoCo和MR Jars的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

JaCoCo和 MultiRelease JAR文件存在问题.由于两个地方都存在相同的类名称,因此JaCoCo抱怨:

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)

我们如何告诉JaCoCo(在Gradle中)从META-INF路径中跳过类?还是根据JVM版本,表现出应有的表现(使用正确的类并忽略其他版本)?

解决方案

如@nullpointer所述,JaCoCo不支持多版本JAR文件.

我的解决方法是忽略版本类.我无法通过显式设置其名称来仅忽略该类,看起来JaCoCo正在扫描所有它们,然后仅在以后应用过滤器进行排除(但也许我错了).

因此,删除版本类的唯一方法是排除所有资源-因为无论如何都不会使用它们.像这样:

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
    }
}

所以我改变了这个:

sourceSets it.sourceSets.main

对此:

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

这里我们明确指出的区别是:sourceSets.main.output.classesDirs排除资源.

来源

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?

解决方案

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

这篇关于JaCoCo和MR Jars的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆