Lombok

Default value in lombok. How to init default with both constructor and builder

一曲冷凌霜 提交于 2019-12-02 20:07:34
I have an object @Data @Builder @NoArgsConstructor @AllArgsConstructor public class UserInfo { private int id; private String nick; private boolean isEmailConfirmed = true; } And I initialize it in two ways UserInfo ui = new UserInfo(); UserInfo ui2 = UserInfo.builder().build(); System.out.println("ui: " + ui.isEmailConfirmed()); System.out.println("ui2: " + ui2.isEmailConfirmed()); Here is output ui: true ui2: false It seems that builder does not get a default value. I add @Builder.Default annotation to my property and my object now looks like this @Data @Builder @NoArgsConstructor

IntelliJ IDEA cannot see Lombok generated code

大城市里の小女人 提交于 2019-12-02 18:44:10
I have a Gradle-based project that uses lombok. I have imported this project into IntelliJ IDEA 14.1 (using the Import External Model import method). I can run the JUnit4 unit tests without problem in Gradle, but IntelliJ seems to have a problem seeing the Lombok generated Getters. This is preventing me from running the tests in IDEA. To make sure it wasn't a set up issue, I created a Very simple project and confirmed that the same issue occurs in the simple test project. My versions: Gradle: gradle-2.3-all via Gradle wrapper Intellij IDEA: IU-141.713 Lombok Plugin: 0.9.2 What am I missing

Required arguments with a lombok @Builder

試著忘記壹切 提交于 2019-12-02 15:43:34
If I add @Builder to a class. The builder method is created. Person.builder().name("john").surname("Smith").build(); I have a requirement where a particular field is required. In this case, the name field is required but the surname is not. Ideally, I would like to declare it like so. Person.builder("john").surname("Smith").build() I can't work out how to do this. I have tried adding the @Builder to a constructor but it didn't work. @Builder public Person(String name) { this.name = name; } You can do it easily with Lombok annotation configuration import lombok.Builder; import lombok.ToString;

mysql8+mybatis-plus3.1自动生成带lombok和swagger和增删改查接口

时光怂恿深爱的人放手 提交于 2019-12-01 21:57:04
mybatis-dsc-generator 还在为写swagger而烦恼吗?还在为忘记写注释而烦恼吗?还在为写简单的api接口而烦恼吗?mybatis-dsc-generator完美集成lombok,swagger的代码生成工具,让你不再为繁琐的注释和简单的接口实现而烦恼:entity集成,格式校验,swagger; dao自动加@ mapper,service自动注释和依赖; 控制器实现单表的增副改查,并实现swaggers的api文档。 源码地址 GitHub: https://github.com/flying-cattle/mybatis-dsc-generator 码云: https://gitee.com/flying-cattle/mybatis-dsc-generator MAVEN地址 2.1.0版本是未集成Mybatis-plus版本——源码分支master <dependency> <groupId>com.github.flying-cattle</groupId> <artifactId>mybatis-dsc-generator</artifactId> <version>2.1.0.RELEASE</version> </dependency> 3.0.0版本是集成了Mybatis-plus版本——源码分支mybatisPlus <dependency

以简单的方式消除 Java 的冗长(Lombok)

十年热恋 提交于 2019-12-01 11:11:23
复制的红薯的,自己只是做一个归档,方便自己看。 ------------------------------------------------------------------------------------ Lombok 是一种 Java Archive (JAR) 文件,可用来消除 Java 代码的冗长。 我们看这样一个例子,一个标准的 Java bean。一个典型的 Java bean 一般具有几个属性。每个属性具有一个 accessor 和 mutator(getter 和 setter)。通常还会有一个 toString() 方法、一个equals() 方法和一个 hashCode() 方法。 初看上去,其中可预见的冗余就已经非常多了。如果每个属性都具有一个 getter 和 setter,并且通常如此,那么又何必详细说明呢? 让我们来看看 Lombok。为了消除代码行,Lombok 使用注释来标识类和 Java 代码块。在前述的那个 Java bean 示例中,所有的 getter、setter 以及其他三个方法都是在编译时被暗示并包括进来的。 而且更好的是如果您使用的是 Eclipse 或 IBM® WebSphere® Studio Application Developer(如果还没用的话,建议最好使用),您就可以将 Lombok 集成到 Java

Can't build maven jhipster project with lombok

☆樱花仙子☆ 提交于 2019-12-01 07:03:47
问题 ./mvnw and mvn clean install fail when adding lombok dependency but run successfully when launched from Intellij IDE Find the error below : INFO] ------------------------------------------------------------- [ERROR] COMPILATION ERROR : [INFO] ------------------------------------------------------------- [ERROR] src/main/java/web/rest/core/service/impl/ProductServiceImpl.java:[18,29] cannot find symbol symbol: method builder() location: class com.test.one.web.rest.core.model.Product Here is

Why IntelliJ needs Lombok plugin?

断了今生、忘了曾经 提交于 2019-12-01 06:54:39
As far as I understand, Lombok uses Java's Annotation Processors to generate additional methods. With Maven 3.5 it works perfectly without adding any additional configuration, just add dependecy to Lombok and put some annotations like @Getter , @Setter . However, if I open this project in IntelliJ IDEA 2018.2, all usages of generated getters/setters are highlighted as errors. I have Annotation Processing turned on, I tried to built project in IntelliJ or build in Maven and then use in IntelliJ, but it still requires Lombok Plugin to avoid false errors. Is it some kind of bug? Error in workflow

BeanUtils not works for chain setter

一笑奈何 提交于 2019-12-01 03:57:56
e.g. class tester { @Test public void testBeanUtils() throws InvocationTargetException, IllegalAccessException, NoSuchMethodException { Stranger stranger = new Stranger(); BeanUtils.setProperty(stranger,"name","wener"); BeanUtils.setProperty(stranger,"xname","xwener"); BeanUtils.setProperty(stranger,"yname","ywener"); System.out.println(stranger); } @Data// lombok annotation generate all setter and getter public static class Stranger { @Accessors(chain = true)// generate chained setter String name; String xname; String yname; public Stranger setYname(String yname)// no lombok, still not work {

Delombok using Gradle

十年热恋 提交于 2019-12-01 02:35:46
As part of our build process we analyse our source code with SonarQube. One problem with this is that we use Lombok annotations and SonarQube is not handling this very well -- our code needs to be 'delombok'ed. Delomboked source removed the annotations and replaces the source file with the final code used by the compiler. This can be done in gradle (see here ). Well, in part. Typically an Ant task can be used to delombok source. Code sample below:- task delombok { // delombok task may depend on other projects already being compiled dependsOn configurations.compile

Delombok using Gradle

柔情痞子 提交于 2019-11-30 22:06:36
问题 As part of our build process we analyse our source code with SonarQube. One problem with this is that we use Lombok annotations and SonarQube is not handling this very well -- our code needs to be 'delombok'ed. Delomboked source removed the annotations and replaces the source file with the final code used by the compiler. This can be done in gradle (see here). Well, in part. Typically an Ant task can be used to delombok source. Code sample below:- task delombok { // delombok task may depend