IntelliJ does not terminate Spring Boot applications build with gradle

17,296

I am pretty sure it's an IntelliJ issue because:

When you run the bootRun from IntelliJ's Gradle integration and then press stop, the application continues to run as you mentioned.

However, if you use the command line and run gradle bootRun and then use Cntrl+C, the application stops just fine.

Note that my setup is Windows 7, IntelliJ 13.1.3, Gradle 1.12 and Spring Boot 1.1.0.M2.

If your need to is to be able to easily debug your application, all you need to do is run the Java (or Groovy) Class that has the main method, since that it is the easiest way to run Spring Boot applications! Kudos to Spring Boot for that!!!

Of course you can continue to use Gradle for tasks like running all the tests or creating the packaged application.

Share:
17,296

Related videos on Youtube

Christian Metzler
Author by

Christian Metzler

Updated on June 07, 2022

Comments

  • Christian Metzler
    Christian Metzler almost 2 years

    I am using IntelliJ 13.1 on Linux and try to build a basic REST application following the example http://spring.io/guides/gs/spring-boot/

    When I execute the target bootRun from within IntelliJ the intergrated tomcat server is started and everything works fine.

    10:09:35: Executing external task 'bootRun'...
    :compileJava UP-TO-DATE
    :processResources UP-TO-DATE
    :classes UP-TO-DATE
    :findMainClass
    :bootRun
    

    But stopping the execution does not affect the gradle task:

    10:11:40: External task execution finished 'bootRun'.
    

    I still can access the tomcat instance on the configured port. Only closing IntelliJ will destroy the process.

    I searched on this topic but could not find any reasonable answers. I wonder if it is a

    • gradle problem (using gradle wrapper version 1.11)
    • Linux problem (Ubuntu 12.04)
    • IntelliJ problem (IDEA 13.1.2)
    • Spring Boot problem (tried different versions from 1.0.0.RELEASE to 1.1.0.M2)
    • Dave Syer
      Dave Syer almost 10 years
      What happens if you use "gradle run"?
    • Christian Metzler
      Christian Metzler almost 10 years
      @DaveSyer Same problem with run. The only way to stop execution is to kill the process.
    • Daryl Teo
      Daryl Teo almost 10 years
      Looks like this is a limitation of Gradle Tooling - it does not allow for termination of long running tasks through the tooling api. There is a workaround: youtrack.jetbrains.com/issue/IDEA-114534
  • Christian Metzler
    Christian Metzler almost 10 years
    So you do not use the gradle integration? But how do you debug your application then?
  • geoand
    geoand almost 10 years
    @ChristianMetzler I do use Gradle Integration, however I limit it to running the tests for the project and running the build process for creating jars or wars. I debug the application simply by running the Spring Boot class that contains the main method!
  • Christian Metzler
    Christian Metzler almost 10 years
    Thanks, if you write it as an answer I will accept it. It works perfect. You should mention to configure it as a single instance for web applications.
  • geoand
    geoand almost 10 years
    @ChristianMetzler I updated my answer. Thanks for the suggestion :)
  • Amr Mostafa
    Amr Mostafa almost 10 years
    I believe it is related to the fact that spring-boot:run forks, and the reason it responds to Ctrl+C is that it manually handles SIGINT and ends the child process.
  • user6123723
    user6123723 over 9 years
    Anybody know if this is ever going to be fixed in Intellij?
  • user1445967
    user1445967 over 8 years
    I was excited to try Christian's suggestion but unfortunately my intellij refuses to run my main class, I can select it in the run configuration but launching it causes classNotFoundException. Maybe because I use the older IntelliJ 13
  • Petri Sirkkala
    Petri Sirkkala over 4 years
    CTRL+Z is not CTRL+C . Use CTRL+C to send SIGINT to process. Unless you want to send the process to background. Background processes sleep and still reserve all the resources they have.