简体   繁体   English

龙目岛与Gradle构建

[英]Gradle build with Lombok

I am trying to develop a web application with SpringBoot and Lombok to reduce boilerplate code. 我试图用SpringBootLombok开发一个Web应用程序以减少样板代码。

While the annotated class works fine, I am getting compilation errors in target classes. 尽管带注释的类工作正常,但目标类中出现编译错误。

I am not trying to compile via IDE but directly via commandline using gradlew build. 我不是试图通过IDE进行编译,而是直接使用gradlew build通过命令行进行编译。

Any suggestion on how to integrate Lombok with gradle to build and generate jars will be really helpful. 关于如何将Lombokgradle集成以构建和生成jar的任何建议都会很有帮助。

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

The error I am getting is: 我得到的错误是:

\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

Customer class is annotated with @Data annotation. 客户类使用@Data注释进行注释。

In the current lombok release 1.18.0 there is an issue with Gradle 4.9 , which will be fixed in the upcoming lombok release 1.18.2. 在当前的lombok版本1.18.0中,Gradle 4.9存在一个问题 ,该问题将在即将发布的lombok版本1.18.2中修复。

If you are using Gradle 4.9, either downgrade Gradle, wait for lombok 1.18.2, or use the current lombok edge release . 如果您使用的是Gradle 4.9,请降级Gradle,等待lombok 1.18.2,或使用当前的lombok edge release

In your Customer class, all the fields that you're trying to initialize in the constructor are non-final. 在您的Customer类中,您要在构造函数中初始化的所有字段都是非最终的。

Since @Data annotation adds only @RequiredArgsConstructor , you cannot initialize non-final fields in the constructor without explicitly annotating this class with @AllArgsConstructor . 由于@Data注释仅添加@RequiredArgsConstructor ,因此,如果不使用@AllArgsConstructor显式注释此类,则无法在构造函数中初始化非最终字段。

So you either need to annotate the class with @AllArgsConstructor , or use setters to initialize the object. 因此,您需要使用@AllArgsConstructor注释类,或使用setter初始化对象。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM