spring-guides/tut-rest

warning: You aren't using a compiler supported by lombok, so lombok will not work and has been disabled. Your processor is: org.gradle.api.internal.tasks.compile.processing.IncrementalProcessingEnvironment Lombok supports: OpenJDK javac, ECJ

geofflangenderfer opened this issue · 3 comments

Problem

unable to make lombok work with either gradle or maven

Solution

removed dependency and did it by hand, which meant:

  • Employee.java
    • generate get, set, toString, equals, and hashCode methods
    • remove lombok import statements
    • remove @Data decorator
  • build.gradle
    • remove any lombok mentions
  • LoadDatabase.java
    • replace log.info with System.out.println
    • remove any sl4j mentions

Working Code

  • Employee.java
package com.example.demo;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;


@Entity
public class Employee {
  private @Id @GeneratedValue Long id;
  private String name;
  private String role;

  Employee() {}

  Employee(String name, String role) {
    this.name = name;
    this.role = role;
  }

  public void setId(Long id) {
    this.id = id;
  }

  public Long getId() {
    return id;
  }

  public void setName(String name) {
    this.name = name;
  }

  public String getName() {
    return name;
  }

  public void setRole(String role) {
    this.role = role;
  }

  public String getRole() {
    return role;
  }

  @Override
  public String toString() {
    return "Employee{" +
      "id = " + getId() +
      ", name = " + getName() +
      ", role = " + getRole() +
      "}";
  }

  @Override
  public int hashCode() {
    int result = 17;
    result = 31 * result + (id != null ? id.hashCode() : 0);
    result = 31 * result + (name != null ? name.hashCode() : 0);
    result = 31 * result + (role != null ? role.hashCode() : 0);
    return result;
  }

  @Override
  public boolean equals(Object o) {
    if (this == o) return true;
    if (o == null || getClass() != o.getClass()) return false;

    Employee object = (Employee) o;

    if (id != null ? !id.equals(object.id) : object.id != null) return false;
    if (name != null ? !name.equals(object.name) : object.name != null) return false;
    return !(role != null ? !role.equals(object.role) : object.role != null);
  }

}
  • build.gradle
plugins {
	id 'org.springframework.boot' version '2.2.5.RELEASE'
	id 'io.spring.dependency-management' version '1.0.9.RELEASE'
	id 'java'
}

group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'

configurations {
	compileOnly {
		extendsFrom annotationProcessor
	}
}

repositories {
	mavenCentral()
}

dependencies {
	implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
	implementation 'org.springframework.boot:spring-boot-starter-web'

	runtimeOnly 'com.h2database:h2'
	testImplementation('org.springframework.boot:spring-boot-starter-test') {
		exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
	}


}

test {
	useJUnitPlatform()
}
  • LoadDatabase.java
package payroll;


import org.springframework.boot.CommandLineRunner;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
class LoadDatabase {

  @Bean
  CommandLineRunner initDatabase(EmployeeRepository repository) {
    return args -> {
      System.out.println("Preloading " + repository.save(new Employee("Bilbo Baggins", "burglar")));
      System.out.println("Preloading " + repository.save(new Employee("Frodo Baggins", "thief")));
    };
  }
}

Are you using OpenJ9 VM by any chance?

I got the same warning message with OpenJDK 14.0.1+7 OpenJ9 .
When I used hotspot variant (default) the warnings went away.

I delomboked the project, so this should no longer be a barrier.

I am not getting the option to delombok. Any other suggestions?