Upgrading to the newest version of JHipster

JHipster provides an upgrade sub-generator (http://www.jhipster.tech/upgrading-an-application/) to help you upgrade an application with a new JHipster version of it. It is quite useful as it automates a lot of manual steps for you, and the only thing you need to do is resolve merge conflicts if there are any after the upgrade is complete. Let's upgrade our application, shall we?

  1. In your Terminal, execute the jhipster upgrade command. The upgrade process will start if there is a new version of JHipster available; otherwise the process will exit.

Once the process starts, you will see a detailed console log of what is going on. As you can see, this sub-generator uses the global JHipster version instead of the local one, unlike other sub-generators:

Using JHipster version installed globally
Executing jhipster:upgrade
Options:
Welcome to the JHipster Upgrade Sub-Generator
This will upgrade your current application codebase to the latest JHipster version
Looking for latest generator-jhipster version...
yarn info v1.5.1
4.14.1
Done in 0.16s.
New generator-jhipster version found: 4.14.1
info git rev-parse -q --is-inside-work-tree
Git repository detected
info git status --porcelain
info git rev-parse -q --abbrev-ref HEAD
info git rev-parse -q --verify jhipster_upgrade
info git checkout --orphan jhipster_upgrade
Created branch jhipster_upgrade
info Removing .angular-cli.json
...
Cleaned up project directory
Installing JHipster 4.13.3 locally
info yarn add generator-jhipster@4.13.3 --dev --no-lockfile --ignore-scripts
yarn add v1.5.1
...
Done in 6.16s.
Installed generator-jhipster@4.13.3
Regenerating application with JHipster 4.13.3...
warning package.json: No license field
/home/deepu/Documents/jhipster-book/online-store/node_modules/.bin
info "/home/deepu/Documents/jhipster-book/online-store/node_modules/.bin/jhipster" --with-entities --force --skip-install
Using JHipster version installed globally
Running default command
Executing jhipster:app
Options: withEntities: true, force: true, skipInstall: true, with-entities: true, skip-install: true
...
Server application generated successfully.
...
Client application generated successfully.
...
Entity generation completed
...
Congratulations, JHipster execution is complete!
Successfully regenerated application with JHipster 4.13.3
info Removing src/main/resources/keystore.jks
info git add -A
info git commit -q -m "Generated with JHipster 4.13.3" -a --allow-empty
Committed with message "Generated with JHipster 4.13.3"
info git checkout -q master
Checked out branch "master"
info git --version
info git merge --strategy=ours -q --no-edit --allow-unrelated-histories jhipster_upgrade
Current code has been generated with version 4.13.3
info git checkout -q jhipster_upgrade
Checked out branch "jhipster_upgrade"
Updating generator-jhipster to 4.14.1 . This might take some time...
info yarn add generator-jhipster@4.14.1 --dev --no-lockfile --ignore-scripts
...
Done in 30.40s.
Updated generator-jhipster to version 4.14.1
info Removing .angular-cli.json
...
Cleaned up project directory
Regenerating application with JHipster 4.14.1...
/home/deepu/Documents/jhipster-book/online-store/node_modules/.bin
info "/home/deepu/Documents/jhipster-book/online-store/node_modules/.bin/jhipster" --with-entities --force --skip-install
Using JHipster version installed globally
Running default command
Executing jhipster:app
Options: withEntities: true, force: true, skipInstall: true, with-entities: true, skip-install: true
...
Entity generation completed
Congratulations, JHipster execution is complete!
Successfully regenerated application with JHipster 4.14.1
info Removing src/main/resources/keystore.jks
info git add -A
info git commit -q -m "Generated with JHipster 4.14.1" -a --allow-empty
Committed with message "Generated with JHipster 4.14.1"
info git checkout -q master
Checked out branch "master"
Merging changes back to master...
info git merge -q jhipster_upgrade
Merge done!
info git diff --name-only --diff-filter=U package.json
WARNING! There are conflicts in package.json, please fix them and then run yarn
Start your Webpack development server with:
yarn start

info git diff --name-only --diff-filter=U
Upgraded successfully.
WARNING! Please fix conflicts listed below and commit!
gradle/wrapper/gradle-wrapper.properties
package.json
src/test/java/com/mycompany/store/web/rest/CustomerResourceIntTest.java

Congratulations, JHipster execution is complete!

The sub-generator does the following in order:

  1. Checks whether there is a new version of JHipster available (not applicable if you are using --force).
  2. Checks whether the application is already initialized as a GIT repository; otherwise, JHipster will initialize one for you and commit the current codebase to the master branch.
  3. Checks to ensure that there are no uncommitted local changes in the repository. The process will exit if it finds any uncommitted changes.
  4. Checks whether a jhipster_upgrade branch exists. If not, a branch is created.

 

  1. Checks out the jhipster_upgrade branch.
  2. Upgrades JHipster to the latest available version globally.
  3. Cleans the current project directory.
  4. Regenerates the application using the jhipster --force --with-entities command.
  5. Commits the generated code to the jhipster_upgrade branch.
  6. Merges the jhipster_upgrade branch back to the original branch from where the jhipster upgrade command was launched.

Let's see what has changed after the upgrade before we resolve the merge conflicts. See the changes staged. Carefully check the changes to make sure everything is in order, especially in the files where we made customizations earlier. My changelog looks like this; note that I truncated the bottom as there were 147 updated files:

Thankfully, we have only three conflicts and hence they should be easy to resolve. The conflict in package.json arises from the change we made to integrate Bootswatch. Carefully resolve the conflict stage in the file and move on to next file.

Once all the conflicts are resolved, stage the files and commit them:

> git add --all
> git commit -am "update to latest JHipster version"

Ensure that everything works. Run the server-side and client-side tests using ./gradlew test && yarn && yarn test, and start the application to verify this by running the ./gradlew clean webpackBuildDev bootRun command.