如何在多模块Maven项目中修复Lombok覆盖率问题

huangapple go评论69阅读模式
英文:

How to fix Lombok coverage in a multi-module maven project

问题

我有一个包含多个Maven模块的项目,每个模块都有实现单元测试。它们通过一个父模块相互依赖。我使用Lombok来为我的模型生成所有样板代码,但通过单元测试,我没有覆盖这些模型上的@Getters和@Setters。

我知道,为了排除这些并提高覆盖率,您可以添加一个包含设置lombok.addLombokGeneratedAnnotation = true的lombok.config文件。我将其添加到了父模块中,但似乎不起作用。是否有一种方法可以为所有模块配置这个?

我还尝试在所有模块中添加不同的lombok.config文件,但仍然没有起作用。这个问题主要影响了SonarQube的覆盖率,因为它不知道应该忽略这些未使用的getter和setter。

附注:在成为多模块项目之前,该项目是一个简单的Maven项目,而这个lombok.config文件是有效的,覆盖率也很好。在将项目转换为多模块方法后,单元测试没有进行任何更改。

英文:

I have a project with multiple maven modules and each of them have unit tests implemented. They depend on each other through a parent module. I'm using Lombok to generate all boiler-plate code for my models and, through the unit tests, i'm not covering the @Getters and @Setters on these models.

I'm aware that, to exclude these and improve your coverage, you can add a lombok.config with the setting lombok.addLombokGeneratedAnnotation = true. I added this in the parent module but this doesn't seem to work. Is there a way to configure this for all modules?

I also tried to add different lombok.config files across all modules and it still didn't work. This issue mostly affects SonarQube coverage, as it is not aware that it should ignore these unused getters and setters.

PS: Before being a multi-module project, the project was a simple maven project and this lombok.config worked, the coverage was good. Nothing was changed in the unit tests after moving the project to a multi-modules approach.

答案1

得分: 3

任何 lombok.config 文件只会影响该目录或其子目录中的 Java 文件。在超级项目中拥有配置文件不会影响子项目或模块中的文件,除非这些源路径位于父项目的源路径之下,我假设这不是情况。

lombok.addLombokGeneratedAnnotation = true 这一行需要出现在每个源目录中的 lombok.config 文件中,才能生效。

英文:

Any lombok.config file will only affect java-files within that directory or below. Having a config-file in a superproject will not affect files in child projects or modules, unless those source-paths are below that of the parent project, which I assume is not the case.

The line lombok.addLombokGeneratedAnnotation = true needs to be in every lombok.config-file within each source directory to be affected.

huangapple
  • 本文由 发表于 2020年8月3日 17:40:03
  • 转载请务必保留本文链接:https://go.coder-hub.com/63227056.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定