SpringBoot结合devtools、AspectJ、Gradle与IntelliJ重启应用的问题
Solutions to Spring DevTools + IntelliJ + Gradle Integration Issues
1. Resource Files Not Deployed to Gradle's build/ Directory
To make IntelliJ use Gradle's output directories instead of its default out/:
- Open Project Structure (Ctrl+Alt+Shift+S) → Navigate to Modules → Select your main application module
- Go to the Paths tab: Uncheck "Inherit project compile output path", set
Output pathtobuild/classes/java/mainandTest output pathtobuild/classes/java/test - Switch to the Resources tab: Verify your resource directories (like
src/main/resources) are mapped correctly, and their output path is set tobuild/resources/main
- Go to the Paths tab: Uncheck "Inherit project compile output path", set
- Ensure Delegate IDE build/run actions to Gradle is enabled in Settings > Build, Execution, Deployment > Build Tools > Gradle > Runner (confirm it's active even if you previously enabled it)
2. AspectJ Compile-Time Weaving (CTW) Not Working with IntelliJ Auto-Compile
IntelliJ's native compiler ignores Gradle's AspectJ configuration. Fix this by:
- Enabling Delegate IDE build/run actions to Gradle (as above) — this forces IntelliJ to use Gradle's build process, which applies your AspectJ plugin and config
- Ensure your
build.gradleincludes proper AspectJ setup (e.g., applying theaspectjplugin, defining aspect dependencies, configuring source sets for aspects) - Replace IntelliJ's "Build project automatically" with Gradle's continuous build: Run
gradle build --continuousin your terminal. This triggers Gradle builds on file changes, ensuring AspectJ weaving is applied correctly, and DevTools will pick up changes from thebuild/directory
3. Duplicate Restart Trigger on Long Compilations
Resolve double restarts by integrating a trigger file with Gradle:
- Add a Gradle task to update a trigger file after build completion:
task triggerDevRestart { doLast { def triggerFile = file("${project.rootDir}/.restart-trigger") triggerFile.text = System.currentTimeMillis().toString() } } // Attach the task to compile and resource processing tasks tasks.withType(JavaCompile) { finalizedBy triggerDevRestart } tasks.processResources { finalizedBy triggerDevRestart } - Configure DevTools to watch this trigger file in
application.properties:spring.devtools.restart.trigger-file=.restart-trigger
This ensures DevTools only restarts once, after Gradle has fully completed building all files. Alternatively, adjust the restart delay to wait for compilation to finish:
spring.devtools.restart.poll-interval=2000 spring.devtools.restart.quiet-period=1000
内容的提问来源于stack exchange,提问作者Janning Vygen
相关产品推荐
相关产品推荐

