Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Preventing JHipster import-jdl from overwriting changes when updating entities

Tags:

jhipster

With my current workflow I have to check in git and manually read changes like added functions after every import-jdl that touches an entitiy I changed.

Is there a way to add functions to the classes JHipster creates without actually changing the files? Like code generation with anotations or extending JHipster created clasees? I feel like I am missing some important documentation from JHipster, I would be grateful for pointers in the right direction.

Thanks!

like image 459
Emmanuel M Avatar asked Feb 13 '20 13:02

Emmanuel M


People also ask

What is JDL JHipster?

The JDL is a JHipster-specific domain language where you can describe all your applications, deployments, entities and their relationships in a single file (or more than one) with a user-friendly syntax.


1 Answers

I faced this problem in one of my projects and I'm afraid there is no easy way to tell JHipster not to overwrite your changes.

The good news is you have two ways of mitigating this and both will make your life much easier.

Update your entities in a separate branch

The idea is to update your entities (execute the import-jdl command) in a different branch and then, once the whole process is finished merge the changes back to master.

This requires no extra changes to your code. The problem I had with this approach is that sometimes the merges were not trivial and I still had to go through a lot of code just to be sure that everything was still in place and working properly.

Do not change the generated code

This is known as the side-by-side practice. The general idea is that you never change the generated code directly, instead you put your custom code in new files and extend the original ones whenever possible.

This way you can update your entities and JHipster will never remove or modify your custom code.

There are two videos available that will teach you (with examples) how to manage this:

  • Custom and Generated Code Side by Side by Antonio Goncalves
  • JHipster side-by-side in practice by David Steiman

In my opinion this is the best approach.

I know this probably isn't the answer you were looking for, but to my knowledge there's no better way.

like image 197
vicpermir Avatar answered Sep 30 '22 17:09

vicpermir