Gradle 使用龙目岛构建

Gradle build with Lombok

我正在尝试使用 SpringBootLombok 开发 Web 应用程序以减少样板代码。

虽然带注释的 class 工作正常,但我在目标 classes 中遇到编译错误。

我不是想通过 IDE 编译,而是直接使用 gradlew build 通过命令行编译。

关于如何将 Lombokgradle 集成以构建和生成 jar 的任何建议都将非常有帮助。

Git 存储库:https://github.com/ashubisht/sample-sbs.git

我得到的错误是:

 \sample-sbs\src\main\java\com\sample\springboot\Controllers\RestControllerClass.java:28:
 error: constructor Customer in class Customer cannot be applied to given types;

 customerDAO.insert(new Customer(1, "Utkarsh", 25));
                               ^
 required: no arguments
 found: int,String,int
 reason: actual and formal argument lists differ in length
 1 error

客户 class 使用 @Data 注释进行注释。

在当前的 lombok 版本 1.18.0 中有 an issue with Gradle 4.9,将在即将发布的 lombok 版本 1.18.2 中修复。

如果您正在使用 Gradle 4.9,请降级 Gradle,等待 lombok 1.18.2,或使用 current lombok edge release.

在您的 Customer class 中,您尝试在构造函数中初始化的所有字段都是非最终字段。

@Data annotation adds only @RequiredArgsConstructor, you cannot initialize non-final fields in the constructor without explicitly annotating this class with @AllArgsConstructor.

所以你要么需要用@AllArgsConstructor注释class,要么使用setter来初始化对象。