Search code examples
springspring-bootgradlespring-boot-devtools

Spring-boot and spring boot dev tools integration not showing the updated class changes


I am trying to follow this example to do spring boot and spring boot dev tools integration to do automatic restart. The classes in the build folder are getting updated when i run build --continuous task but the application still talks to the old classes. In the example the bootRun task is as below. My project has its custom task for running the application. Right now with build -continuous when I make a change the application it is rebuilding the classes but the running application is not showing the changes. How to change my custom h2Run task so that it loads the changed classes? Thank you.

The boot run task in the example

bootRun {
    classpath = sourceSets.main.runtimeClasspath + configurations.dev
}

My custom task for bootRun

class Run extends JavaExec {
    Run() {
        group "application"
        dependsOn project.tasks.classes, project.tasks.pathingJar
        classpath = project.files("$project.buildDir/classes/main", "$project.buildDir/resources/main", project.tasks.pathingJar.archivePath)
        main = "com.mycompany.Application"
    }
}

task h2Run(type: Run) {
    classpath = sourceSets.main.runtimeClasspath + configurations.dev // this is not working
    description "Start $appName using H2 database"
    args "--spring.profiles.active=dev"
    mustRunAfter 'cleanH2'
    dependsOn copyContentTypeLibraries
}

Solution

  • I walked through the DZone article you linked to. I didn't add your custom Run class or task, I just grabbed the bootRun task right out of the article. Even without any of your custom code, I initially experienced the same behavior you do.

    The article states:

    1. At the first terminal, start Gradle build as a continuous task: gradle build --continuous

    2. At the second terminal, start the Gradle bootRun task: gradle bootRun

    If I do these things, in this order, I also see my classes recompile, but the servlet container doesn't pick the changes up. Just like you describe.

    However, if I do gradle bootRun first, and gradle build --continuous second, after the application is running, the application restarts as expected whenever I edit a java file.

    Have you tried executing the commands in the two terminal windows in reverse order?