Skip to content

Instantly share code, notes, and snippets.

@gmarziou
Last active July 31, 2018 11:30
Show Gist options
  • Save gmarziou/6cc0788f8e7cb21a61a7b14f32b9a657 to your computer and use it in GitHub Desktop.
Save gmarziou/6cc0788f8e7cb21a61a7b14f32b9a657 to your computer and use it in GitHub Desktop.
Managing custom code in JHipster using git

This is just an example which is not complete but gives some hints how to re-generate code while keeping your custom changes.

To simplify, custom development is committed directly on git master branch.

Generate the app with JHipster 4.13.3

yarn global add [email protected]
mkdir keep-changes
cd keep-changes
jhipster

The initial generation is committed to git as you can see using git log.

Let's create a branch jhipster_upgrade that will be used to archive generated code, it's the same branch used by the upgrade generator:

git checkout -b jhipster_upgrade

Create a new entity Book in a JDL file entities.jh

entity Book (book) {
  title String
}
jhipster import-jdl entities.jh

git add .
git commit -m "Generation of Book entity"
git checkout master

git merge jhipster_upgrade

Edit Book.java and add some comments to javadoc and a new method.

git add src/main/java
git commit -m "Custom changes to Book.java"

Switch to jhipster_upgrade branch to generate more code that impacts Book entity that we have already customized:

git checkout jhipster_upgrade

Edit entities.jh to modify Book entity and add a new entity Author

entity Author (author) {
  name String
}

entity Book (book) {
  title String,
  price Integer
}

relationship OneToMany {
  Author{book} to Book{writer(name) required}
}
jhipster import-jdl entities.jh
git add .
git commit -m "Add Author and Book price"             

TODO: maybe we could implement the equivalent to jhipster --with-entities for JDL?

TODO: mention Liquibase

git checkout master
git merge -s recursive -Xours jhipster-reference

TODO: should we keep jhipster_upgrade branch and push it to our server?

Change options of all entities

git checkout -b modify-entity-options

Edit entities.jh

dto * with mapstruct
paginate * with infinite-scroll
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment