Spring Boot Kotlin项目自动构建重启失效问题排查求助
I understand you're having trouble getting Spring Boot DevTools to auto-restart your Kotlin project after file changes, even after configuring the dependency and adjusting IntelliJ settings. Let’s go through targeted troubleshooting steps to resolve this:
1. Verify DevTools Dependency & Configuration
Your build.gradle.kts setup looks correct for DevTools (using developmentOnly configuration and extending runtimeClasspath), but double-check these details:
- Ensure no other dependencies or configurations are excluding
spring-boot-devtoolsfrom the runtime classpath. - Confirm there’s no explicit disablement in your application config (e.g.,
spring.devtools.restart.enabled=falseinapplication.propertiesorapplication.yml).
2. Fix IntelliJ’s Auto-Compile & Runtime Settings
This is the most common culprit for DevTools not triggering restarts. Even if you think you’ve set these, recheck:
- Enable automatic project building:
Go toFile > Settings > Build, Execution, Deployment > Compilerand tick the box for Build project automatically. - Allow auto-make while applications are running:
PressCtrl+Shift+A(Windows/Linux) orCmd+Shift+A(Mac), search for "Registry", then find and enable thecompiler.automake.allow.when.app.runningoption. - Check run configuration environment variables:
OpenRun > Edit Configurations, select your Spring Boot run configuration, go to the Configuration tab, and ensure the environment variables includeSPRING_DEVTOOLS_RESTART_ENABLED=true(or don’t explicitly set it tofalse).
3. Confirm Kotlin Compilation Output is Monitored
DevTools watches the default compilation output directories (build/classes/java/main and build/classes/kotlin/main). Your KotlinCompile task is set to target JVM 1.8, matching your Java source compatibility—this is correct. To ensure changes are compiled to these directories:
- Make sure you’re not using a custom output directory in your Gradle config that DevTools isn’t monitoring.
- Test manually compiling the project with
./gradlew compileKotlinand check if the output files update; if they do, DevTools should pick up the change.
4. Check DevTools Restart Exclusions/Inclusions
If you’ve added any custom spring.devtools.restart.exclude or spring.devtools.restart.additional-paths properties, they might be preventing restarts:
- Temporarily comment out these properties in your application config to rule out exclusion of your modified files.
- If you need to monitor additional paths (like static resources or templates), ensure they’re added to
spring.devtools.restart.additional-paths.
5. Run the Project via Gradle’s bootRun Task
Sometimes running the project through IntelliJ’s default Java run configuration can bypass DevTools triggers. Try starting the project using Gradle’s official task:
- In IntelliJ’s Gradle tool window, run
Tasks > application > bootRun. - Make a code change and see if the auto-restart triggers.
6. Clear IntelliJ Caches
Corrupted caches can interfere with auto-compilation and DevTools behavior:
- Go to
File > Invalidate Caches..., select Invalidate and Restart to clear all caches and restart the IDE.
After going through these steps, your DevTools auto-restart should start working as expected. Start with the IntelliJ settings (step 2) since those are the most frequent fix for this issue.
内容的提问来源于stack exchange,提问作者久保圭司

