3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

JUnit 5がgradle testするとlombokのアノテーションでエラーになる

Posted at

現象

以下のように、gradle testするとJUnit 5がlombokが云々で実行に失敗する。

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

原因と解決策

https://medium.com/@tsuyoshiushio/gradle-5-0-with-lombok-and-spring-boot-e8ca564fc552 にあるように、testCompileOnlytestAnnotationProcessorでlombokを入れる。詳細は良く理解してないが、lombokのアノテーション処理がtest時も有効になるよう設定しないといけないのだろう。

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

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?