I'm working on a new multi module Maven project (Java11 ) as we added more and more unit tests to our project I noticed that compiling our tests was getting really slow. So I started profiling the project and here are the results for compiling a typical module:
- "test-compile" took 109s for 18 files
- "compile" (non test classes) took 4s for 76 files.
I have run this on my Windows notebook with Java11 (OpenJDK) but can reproduce it in Java17 and OracleJDK and also on Linux machines. I have no idea what's causing this vast difference (0.05s per file vs. 6s per file). We are using mainly Spring-Boot and for our tests we use Junit5 with spring-boot-starter-test, Mockito and AssertJ.
Here is a minimal reproducer using our maven config: https://github.com/elbird/slow-test-compile
CodePudding user response:
After a lot of trial and error I found the culprit: lombok.
I cannot explain why but in my reproducer https://github.com/elbird/slow-test-compile I found that lombok at least in version 1.18.20 (and lower) is really slow when compiling with Java11 . (especially with heavly overloaded methods like assertjs assertThat()
)
Luckily with lombok 1.18.22 this issue seems to be fixed. The fix seems to be related to this Bug: https://github.com/projectlombok/lombok/issues/2652 which is fixed with the following changelog entry:
IMPROBABLE BREAKING CHANGE: If the underlying compiler and --release / --source option is 10 or higher, lombok's val is now replaced by final var.
https://projectlombok.org/changelog
TLDR: update to lombok 1.18.22 fixed the issue.