79.4.2 使用Gradle和IntelliJ IDEA配置Spring Loaded

如果想将Spring Loaded和Gradle,IntelliJ IDEA结合起来,那你需要付出代价。默认情况下,IntelliJ IDEA将类编译到一个跟Gradle不同的位置,这会导致Spring Loaded监控失败。

为了正确配置IntelliJ IDEA,你可以使用idea Gradle插件:

  1. buildscript {
  2. repositories { jcenter() }
  3. dependencies {
  4. classpath "org.springframework.boot:spring-boot-gradle-plugin:1.4.1.RELEASE"
  5. classpath 'org.springframework:springloaded:1.2.0.RELEASE'
  6. }
  7. }
  8. apply plugin: 'idea'
  9. idea {
  10. module {
  11. inheritOutputDirs = false
  12. outputDir = file("$buildDir/classes/main/")
  13. }
  14. }
  15. // ...

IntelliJ IDEA必须配置跟命令行Gradle任务相同的Java版本,并且springloaded必须作为一个buildscript依赖被包含进去。

此外,你也可以启用Intellij IDEA内部的Make Project Automatically,这样不管什么时候只要文件被保存都会自动编译。