【发布时间】:2019-01-06 12:31:51
【问题描述】:
我正在 IntelliJ IDEA 2018.3 社区中从事基于 Gradle 的 Spring Boot 2 项目。
我想让 Spring Boot 的 自动重启 工作,这样当我在 IDE 中编辑文件时,IDE 会即时重新编译它(而不将其委托给 Gradle),运行Spring Boot 实例看到更新的类文件并重新启动部分应用程序。
我有:
- 将
spring-boot-devtools添加到我的项目的依赖项中 - 在设置/构建-执行-部署/编译器中启用“自动构建项目”
- 在注册表中启用
compiler.automake.allow.when.app.running
但我仍然无法让自动重启工作。
问题似乎是 IDEA 将编译后的类放在 out 目录中,而不是 Gradle 的 build 目录中。此外,编译后的类(和更新的资源文件)被放置在与 Gradle 不同的子目录结构中。这显然是well-known "feature" of IDEA, as in "Works As Intended."
out/
production/ <- different
classes/
(package)/
MyClass.class
resources/
templates/
test.html
build/
classes/
kotlin/ <- different
main/ <- different
(package)/
MyClass.class
resources/
main/ <- different
templates/
test.html
那么,考虑到 IDEA 的这个“特性”,我怎样才能让 Spring Boot 的自动重启/实时重新加载工作呢?
【问题讨论】:
-
@CrazyCoder 是的,我看到了那个讨论。在这里,我特别询问是否有人知道使自动重启工作的方法。我尝试了其中列出的一些选项,但无济于事。
-
您已经尝试过该解决方案并且构建目录没有改变?或者它改变了,但它仍然没有重新启动?如果是后者,您的问题标题具有误导性。
-
@CrazyCoder 该解决方案错误或不完整。首先,通过应用这些指令,IDEA 将输出文件放入
build/classes/main/(package)/MyClass.class和build/classes/main/templates/test.html,这仍然与 Gradle 的预期不同(build/classes/kotlin/main/(package)/MyClass.class和build/resources/main/templates/test.html)其次,通过更改sourceSets,Spring Boot不再起作用:“尚未配置主类名,无法解析。”所以它离一个可行的解决方案还很远。如果你能修复它,请在下面发布!
标签: spring-boot gradle intellij-idea