Friday, August 26, 2022
HomeWordPress DevelopmentJHipster doesn't use lombok. Why?

JHipster doesn’t use lombok. Why?


After I run the JHipster generator for the primary time I noticed that the again finish applied with spring boot does not use Lombok. So I made a decision to customise the generated code to make use of lombok than I noticed it wasn’t the easiest way to make use of JHipster.



Customise JHipster

When I noticed how superior JHipster was I assumed that I ought to change the generated code to be just like the one I used to kind manually. So I noticed the chance to create my very own blueprint with the next customized annotations:

  • Add Lombok – @lombok
  • Cover remark – @noCodeComment
  • Change the database scheme – @schema
  • Add Id GeneratedValue to entity – @generatedValue(identification)
  • Outline column database title – @column(ds_field)
  • Use unsupported sorts – @newFieldTypeImport(import_class_package_type) and @newFieldType(kind)

I opened supply my blueprint which customise the server aspect code:

Here’s a jdl file instance which makes use of my blueprint:

@lombok  
@schema(MyProject)  
@noCodeComment 
entity RenanClasse (RenanOk) {  
@generatedValue(identification)  
id Lengthy  
@column(ds_name)  
title String
@newFieldTypeImport(java_time_LocalDateTime)  
@newFieldType(LocalDateTime)  
birthday ZonedDateTime
}  

// Use Knowledge Switch Objects (DTO)  
dto * with mapstruct  

// Service layer  
service all with serviceClass  
Enter fullscreen mode

Exit fullscreen mode



JHipster select not use Lombok

I discovered an problem at jhipster generated undertaking that checklist the the explanations to not use lombok. I’ll quote a few of them:

  1. > On one undertaking, a brand new model of the Lombok plugin brought on the IDE to crash (I feel this was Intellij). So no person may work anymore.
  2. > On one other undertaking, Lombok made the CI server crash (and would have in all probability brought on the manufacturing server to crash), because it triggered a bug within the JVM
  3. > On a 3rd undertaking, we achieved 30% efficiency improve by recoding the equals/hashcode from Lombok
  4. > Then, for JHipster, the story can be that we will not ask individuals to put in a plugin on their IDE:
    > – 1st objective is to have a clean expertise: you generate the app and it really works in your IDE, by default
    > – 2nd objective is that you should use no matter IDE you need. And a few individuals have very unique issues, for instance I simply tried https://codenvy.com/ -> no plugin for this one, in fact



Entity implementation

Within the following instance you’ll be able to see that JHipster implements manually units and will get. Past which you could see it is implement what known as fluent technique as I be taught it from the JHipster generator supply code and from this problem which debate fluent setters implementation at jhipster.

@Entity
@Desk(title = "nap")
@Cache(utilization = CacheConcurrencyStrategy.READ_WRITE)
public class Nap implements Serializable {

    non-public static remaining lengthy serialVersionUID = 1L;

    @Id
    @GeneratedValue(technique = GenerationType.SEQUENCE, generator = "sequenceGenerator")
    @SequenceGenerator(title = "sequenceGenerator")
    @Column(title = "id")
    non-public Lengthy id;

    @Column(title = "begin")
    non-public ZonedDateTime begin;

    @Column(title = "jhi_end")
    non-public ZonedDateTime finish;

    @Enumerated(EnumType.STRING)
    @Column(title = "place")
    non-public Place place;

    @ManyToOne
    non-public BabyProfile babyProfile;

    @ManyToOne
    non-public Humor humor;

    // jhipster-needle-entity-add-field - JHipster will add fields right here

    public Lengthy getId() {
        return this.id;
    }

    public Nap id(Lengthy id) {
        this.setId(id);
        return this;
    }

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

    public ZonedDateTime getStart() {
        return this.begin;
    }

    public Nap begin(ZonedDateTime begin) {
        this.setStart(begin);
        return this;
    }

    public void setStart(ZonedDateTime begin) {
        this.begin = begin;
    }

    public ZonedDateTime getEnd() {
        return this.finish;
    }

    public Nap finish(ZonedDateTime finish) {
        this.setEnd(finish);
        return this;
    }

    public void setEnd(ZonedDateTime finish) {
        this.finish = finish;
    }

    public Place getPlace() {
        return this.place;
    }

    public Nap place(Place place) {
        this.setPlace(place);
        return this;
    }

    public void setPlace(Place place) {
        this.place = place;
    }

    public BabyProfile getBabyProfile() {
        return this.babyProfile;
    }

    public void setBabyProfile(BabyProfile babyProfile) {
        this.babyProfile = babyProfile;
    }

    public Nap babyProfile(BabyProfile babyProfile) {
        this.setBabyProfile(babyProfile);
        return this;
    }

    public Humor getHumor() {
        return this.humor;
    }

    public void setHumor(Humor humor) {
        this.humor = humor;
    }

    public Nap humor(Humor humor) {
        this.setHumor(humor);
        return this;
    }

    // jhipster-needle-entity-add-getters-setters - JHipster will add getters and setters right here

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (!(o instanceof Nap)) {
            return false;
        }
        return id != null && id.equals(((Nap) o).id);
    }

    @Override
    public int hashCode() {
        // see https://vladmihalcea.com/how-to-implement-equals-and-hashcode-using-the-jpa-entity-identifier/
        return getClass().hashCode();
    }

    // prettier-ignore
    @Override
    public String toString() {
        return "Nap{" +
            "id=" + getId() +
            ", begin="" + getStart() + """ +
            ", finish='" + getEnd() + "'" +
            ", place="" + getPlace() + """ +
            "}";
    }
}
Enter fullscreen mode

Exit fullscreen mode

supply: Nap.java

So you’ll be able to create this object like if you use the builder sample however it’s not immutable.

Nap nap = new Nap().id(1l).begin(ZonedDateTime.now()).finish(ZonedDateTime.now().plusHours(1));
Enter fullscreen mode

Exit fullscreen mode

I loved this implementation and that is sufficient for me to maintain my code much less verbose.



That is the way in which

I gave as much as customise JHipster generated code.
I noticed that I ought to settle for the jhipster generated code sample as a result of If I attempt to customise every thing I’m creating my very own JHipster and I’m going to lose the productiveness which JHipster may convey to my workflow.
It is not a trivial job to take care of a blueprint updated with the most recent jhipster generator model. So I counsel you to solely create a blueprint if this can be very vital.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments