[JAVA] JUnit 5 gradle test fails with lombok annotation

phenomenon

As shown below, when `` `gradle test``` is done, JUnit 5 fails to execute due to lombok and so on.

> gradle test
Hoge.java:3: error: package lombok does not exist
import lombok.Data;
             ^
Hoge.java:5: error: cannot find symbol
@Data
 ^
  symbol: class Data
2 errors

FAILURE: Build failed with an exception.

Cause and solution

lombok with `` `testCompileOnlyand testAnnotationProcessor```, as at https://medium.com/@tsuyoshiushio/gradle-5-0-with-lombok-and-spring-boot-e8ca564fc552 Put in. I don't understand the details well, but I think I have to set lombok annotation processing to be effective even at test time.

dependencies {
    compileOnly("org.projectlombok:lombok:${lombokVersion}")
    testCompileOnly("org.projectlombok:lombok:${lombokVersion}")
    annotationProcessor("org.projectlombok:lombok:${lombokVersion}")
    testAnnotationProcessor("org.projectlombok:lombok:${lombokVersion}")
}

Recommended Posts

JUnit 5 gradle test fails with lombok annotation
Java automated test implementation with JUnit 5 + Gradle
Unit test with Junit.
Test Web API with junit
JUnit 5 fails with java.lang.NoSuchMethodError: org.junit.platform.launcher.Launcher.execute
Lombok not working with Gradle5
Remote debugging with Gradle test
Output test coverage with clover + gradle
I can't install lombok with Gradle.
[Java] Test private methods with JUnit
Test Spring framework controller with Junit
How to filter JUnit Test in Gradle
Control test order in Junit4 with enumeration
How to test private scope with JUnit
rails test fails with database reference error
[Java] How to test for null with JUnit
[CircleCI 2.0] [Java] [Maven] [JUnit] Aggregate JUnit test results with CircleCI 2.0
Java automated test implementation with JUnit 5 + Apache Maven
How to test interrupts during Thread.sleep with JUnit
Build and test Java + Gradle applications with Wercker
Easy JUnit test of Elasticsearch 2018 version with embedded-elasticsearch
Accelerate Selenium execution time with JUnit ClassRule annotation
Test code using mock with JUnit (EasyMock center)
Mixin test cases with JUnit 5 and default methods
Test the contents of an Excel file with JUnit
[JUnit 5 compatible] Write a test using JUnit 5 with Spring boot 2.2, 2.3
[JUnit 5] Write a validation test with Spring Boot! [Parameterization test]
WebAPI unit test and integration test with SpringBoot + Junit5, 4 patterns
I wrote a test with Spring Boot + JUnit 5 now
Use ProGuard with Gradle
Lombok with VS Code
Try JUnit test launch
Install Gradle with ubuntu16.04
DataNucleus starting with Gradle
[Rails] Test with RSpec
Test Nokogiri with Rspec.
Automatically test with Gauge
Load test with JMeter
Use WebJars with Gradle
Get started with Gradle
Use jlink with gradle
[Java] I want to test standard input & standard output with JUnit