15

My goal is:

  1. Disable autosave in IntelliJ IDEA for a spring boot project

  2. Hot reload the project always when files are manually saved

Seems to me that it is impossible to achieve these two goals simultaneously.

I can disable autosave in IntelliJ IDEA by modifying these settings:

Build, Execution, Deployment -> Compiler Uncheck Build project automatically

Also I think what is too needed is modify these options:

Appearance & Behaviour -> System Settings Uncheck both save files under Synchronization (frame deactivation and save files automatically)

I can enable hot reload by the help of Mkyong: Mkyong-help As you can see from the link, it requires setting 'Build project automatically' on. If I do both of these steps, then the application will always save on edit, and it will always hot reload the app.

This is so frustrating, I thought IntelliJ IDEA was a good modern IDE, with these kind of industrial core features like hot reloading handled easy?

The problem is, that I really don't want to hot reload my application on every change I make to the files! Because then it will be continuously hot reloading, which will break the application most of the time. Just so unnecessary and wasting resources. I want to hot reload always when I manually save a file, which is a standard for so many other editors. There has to be a solution for this problem, because people want reasonable hot reload for their development.

CrazyCoder
  • 389,263
  • 172
  • 990
  • 904
Ville Miekk-oja
  • 18,749
  • 32
  • 70
  • 106

4 Answers4

24

As far as I understand, your issue is that you want the spring server to reload automatically whenever you make changes and then manually save them. Right? if the that is the case, follow my steps and hopefully you will get what desire.

1. include the spring-boot-devtools dependency

Maven

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <optional>true</optional>
    </dependency>
</dependencies>

Gradle

dependencies {
    compile("org.springframework.boot:spring-boot-devtools")
}

2. enable “Make project automatically” in the compiler preferences for automatic restarts to work.

enter image description here

3. enable the compiler.automake.allow.when.app.running registry setting in IntelliJ. You can access the registry in IntelliJ using the shortcut Shift+Command+A, then searching for registry.

enter image description here


The 3rd step will make building your project (make project) automatic when you save you changes manually.

======================================================================== These steps will enforce spring server to reboot once changes has been saved manually via your IDE. However, you need to refresh your browser every time you make a change even though the server is rebooted. To enforce your browser to refresh automatically as well, you need an extension installed in your browser called Live Reload. Check this link http://livereload.com/extensions/. the link will show you how to install this extension depends on your browser.

Faisal Julaidan
  • 388
  • 4
  • 16
  • 7
    This works for me, but I feel there is some delay in triggering it up after I hit `Cmd+S` to save. Is there any delay to decrease in those registry settings? – krozaine Sep 20 '18 at 19:13
  • 1
    For someone who do not know how to open the Registry setting, reference https://stackoverflow.com/questions/28415695/how-do-you-set-a-value-in-the-intellij-registry – Hank Feb 24 '19 at 06:05
  • If you are using OS X, you can open the registry by typing 'cmd + shift + A'. Type 'registry' and change the value of the option you're looking for. – Eric Feb 25 '19 at 08:54
  • @krozaine did you manage to solve the delay? I'm having the same issue. – Mirceac21 Aug 18 '19 at 07:00
  • 2
    @Mirceac21 there is `compiler.automake.trigger.delay` in registry settings. Please check if this helps – krozaine Aug 20 '19 at 17:57
  • 5
    I know its an old question.. but. In the current Version of IntelliJ the 'compiler.automate...' registry setting is not longer available. Does anyone know something about an new option? – Yannick Oct 08 '21 at 11:07
  • 3
    @Yannick you can find it under "Advanced Settings", it's called "Allow auto-make to start even if developed application is currently running". Source: https://stackoverflow.com/a/68730328 – marcotama Jan 31 '22 at 11:23
4

In IntelliJ 2021.2 you only have to click this option https://youtrack.jetbrains.com/api/files/74-1125614?sign=MTYzMDgwMDAwMDAwMHwxMS04NzUyMzF8NzQtMTEyNTYxNHxON0lqdXpkVUo4ZG1VOGlqMjRsQkY3%0D%0AVjRXbHJlQ1oxM0hfaE0tVGd0cG9zDQo%0D%0A&updated=1627651335092

enter image description here

karel
  • 5,489
  • 46
  • 45
  • 50
Erwin Ronco
  • 49
  • 1
  • 1
  • 2
    While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. – Tyler2P Sep 02 '21 at 08:00
  • Please add further details to expand on your answer, such as working code or documentation citations. – Community Sep 02 '21 at 08:00
1

Here's a simple workflow that works well for me in IDEA Ultimate Edition and does not restart parts of the application when the code is hot swapped:

1. Install Spring Boot Developer Tools

2. Create a proper Spring Boot run configuration

The crucial step here is to set the On 'Update' action to Hot swap classes and update trigger file if failed Settings Here's the tooltip's explanation of the various options. Specifying only Update classes or resources would work, but parts of your application would be reloaded, but much faster than if you started the application from scratch. See the Restart vs Reload section of the documentation for an explanation.
Tooltip

3. Run your Spring Boot application in debug mode Shift + F9

4. Change some java files or static content and press CTRL + F10

It will update classes and resources you just changed. For good results, disable your browser's cache to avoid seeing old versions of static resources.

5. Editing templates

If you're using templating engines, the documentation provides instructions about how to reload them without restarting the container

6. (Optional) Trigger a browser refresh with LiveReload

Spring Boot Developer Tools contain a LiveReload server which helps you trigger browser reloads whenever the content changes.

JohnEye
  • 6,436
  • 4
  • 41
  • 67
  • There is another way here (under updated) that does not involve manually updating application (CTRL-F10) https://stackoverflow.com/questions/76839843/springboot-update-classes-without-restarting-tomcat-server – Radika Moonesinghe Aug 05 '23 at 19:31
1

I am using the Below Version of Community Edition

IntelliJ IDEA 2021.2.2(Community Edition)

And Below Are the Steps I performed to Hot Reload on Manual Save.

Step 1 added spring-boot-dev-tools dependency in Maven dependency pom.xml

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <optional>true</optional>
    </dependency>

Step 2
Compiler Configuration for picking build Automatically

Step 3
Advance Compiler Setting for Restart on Manual Save