You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Spring Boot Kotlin项目自动构建重启失效问题排查求助

Troubleshooting Spring Boot DevTools Auto-Restart for Kotlin Projects

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-devtools from the runtime classpath.
  • Confirm there’s no explicit disablement in your application config (e.g., spring.devtools.restart.enabled=false in application.properties or application.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 to File > Settings > Build, Execution, Deployment > Compiler and tick the box for Build project automatically.
  • Allow auto-make while applications are running:
    Press Ctrl+Shift+A (Windows/Linux) or Cmd+Shift+A (Mac), search for "Registry", then find and enable the compiler.automake.allow.when.app.running option.
  • Check run configuration environment variables:
    Open Run > Edit Configurations, select your Spring Boot run configuration, go to the Configuration tab, and ensure the environment variables include SPRING_DEVTOOLS_RESTART_ENABLED=true (or don’t explicitly set it to false).

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 compileKotlin and 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,提问作者久保圭司

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.14 08:32:00