JaCoCo忽略了Lombok代码,这是预期的吗? [英] JaCoCo ignoring Lombok code, is this expected?
问题描述
我正在使用Lombok 1.18.2和JaCoCo 0.8.3,它们在理论上可以识别/忽略lombok注释.我做了一个测试,在lombok.config
中添加了lombok.addLombokGeneratedAnnotation = true
参数,然后在目标类中看到了生成的注释,反编译了代码.
I am using Lombok 1.18.2 and JaCoCo 0.8.3, which theoretically recognize/ignore lombok annotations. I did a test, added the lombok.addLombokGeneratedAnnotation = true
param in my lombok.config
and then I see the generated annotation on my target classes decompiled code.
但是我很惊讶地打开了jacoco.exec文件,看到类似@Getter的东西增加了"Total Probes"的值,但保持不变的是"Executed Probes". 这是预期的吗?
But I am surprised to open jacoco.exec file and see that things like @Getter increase the "Total Probes" values, but keep untouched the "Executed Probes" one. Is this expected?
如果是这样,SonarQube如何巧妙地使用它,如果将其指向jacoco.exec文件,则仅包含有关总/命中探测的信息?声纳如何分辨其中一个探头与龙目岛有关?
If so, how can SonarQube make smart use of it, if by pointing it to the jacoco.exec files, there is only information on total/hit probes? How can Sonar tell one of this probes has something to do with lombok?
推荐答案
我正在使用Lombok 1.18.2和JaCoCo 0.8.3,它们在理论上可以识别/忽略lombok注释.
I am using Lombok 1.18.2 and JaCoCo 0.8.3, which theoretically recognize/ignore lombok annotations.
Not theoretically, but practically.
不是忽略lombok注释",而是以 @lombok.Generated
,甚至是来自0.8.3 changelog 的更精确的报价条目:>
Not "ignore lombok annotations", but methods annotated with @lombok.Generated
, or even more precise quoting entry from 0.8.3 changelog:
由注释注释的类和方法,其保留策略为运行时或类,并且其简单名称包含"Generated"(以前需要相等),在生成报告的过程中被过滤掉了
Classes and methods annotated by annotation whose retention policy is runtime or class and whose simple name contains "Generated" (previously equality was required) are filtered out during generation of report
但是我很惊讶地打开了jacoco.exec文件,看到类似@Getter的东西增加了"Total Probes"的值,但保持不变的是"Executed Probes".这是预期的吗?
But I am surprised to open jacoco.exec file and see that things like @Getter increase the "Total Probes" values, but keep untouched the "Executed Probes" one. Is this expected?
是的,这是预期的.在类的检测(插入探针)期间不会进行方法的过滤. exec
文件不是最终报告,它包含有关插入到类中的所有探针的原始信息.方法的过滤发生在生成报告(分析exec
和class
文件)的过程中,即在执行 report
JaCoCo Ant Task .
Yes, this is expected. Filtering of methods doesn't happen during instrumentation of classes (insertion of probes). exec
file is not final report, it contains raw information about all probes inserted in class. Filtering of methods happens during generation of report (analysis of exec
and class
files), i.e. during execution of report
JaCoCo Ant Task for example.
如果是这样,SonarQube如何巧妙地使用它,如果将其指向jacoco.exec文件,则仅包含有关总/命中探测的信息?声纳如何分辨其中一个探头与龙目岛有关?
If so, how can SonarQube make smart use of it, if by pointing it to the jacoco.exec files, there is only information on total/hit probes? How can Sonar tell one of this probes has something to do with lombok?
SonarQube 将JaCoCo嵌入为库和
SonarQube embeds JaCoCo as a library and use it to analyze exec
and class files for generation of their report.
这就是JaCoCo发布公告通常包含以下声明的原因,例如对于 0.8.2 :
And that's why JaCoCo release announcements usually contain following statement, e.g. for 0.8.2:
和以前一样-请注意
As before - please note
我们作为JaCoCo项目的一部分开发的集成的
0.8.2版本(Ant Tasks,Maven插件和命令行界面)提供Java 11支持和新的过滤器,
0.8.2 version of integrations developed as part of JaCoCo project by us (Ant Tasks, Maven Plugin and Command Line Interface) provide Java 11 support and new filters,
工具将提供分析Java 11类文件并仅在它们更新到此版本的JaCoCo后使用新过滤器的功能. . 因此,请关注/等待/等各个供应商,例如
tools that directly read exec files (which is not a final report) and embed JaCoCo as a library for generation of report will provide ability to analyze Java 11 class files and to use new filters only after they updated to this version of JaCoCo. So please follow/wait/etc respective vendors such as
SonarQube- https://jira.sonarsource.com/browse/SONARJAVA-2876,或尝试使用读取XML报告的新插件- https://github.com/SonarSource/声纳雅各布
SonarQube - https://jira.sonarsource.com/browse/SONARJAVA-2876 , or try to use new plugin that reads XML report - https://github.com/SonarSource/sonar-jacoco
这篇关于JaCoCo忽略了Lombok代码,这是预期的吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!