Spring Boot + Gradle + IntelliJ IDEA 的环境 + Spring Loaded

为了实现某个特定的目标或达到某个预定的结果。

使用Spring Boot、Gradle和Intellij IDEA开发环境很方便,但要查看执行结果,需要多次运行gradle bootRun并重新启动。

为了可以在不多次运行gradle bootRun的情况下反映源代码的更改结果,我们可以通过引入Spring Loaded并在gradle bootRun命令中启动应用程序来实现。

环境

    • Gradle 2.1

 

    • intelliJ IDEA 14

 

    • Spring Boot 1.1.9

 

    Spring loaded 1.2.1

步骤

1. 创建build.gradle文件

以下是模板。

以下是样板。

以下是范本。

以下是模板文件。

以下是模板示例。

buildscript {
    repositories {
        mavenLocal()
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:1.1.9.RELEASE")
        classpath("org.springframework:springloaded:1.2.1.RELEASE")
    }
}

apply plugin: 'idea'
apply plugin: 'spring-boot'

idea {
    module {
        inheritOutputDirs = false
        outputDir = file("$buildDir/classes/main/")
    }
}

repositories {
    mavenLocal()
    mavenCentral()
}

dependencies {
    compile("org.springframework.boot:spring-boot-starter-web:1.1.9.RELEASE")

}

我們需要設定idea block,以便使IntelliJ IDEA編譯的檔案與Gradle編譯的檔案相同。

2. IntelliJ IDEA的自动编译设置

我的IntelliJ IDEA默认没有开启自动编译。(我无法确定是不是默认就没有编译,或者是我之前更改了设置……)

启用自动编译。

自动编译启用步骤

    1. 打开【⌘.】软件,进入【Preferences】菜单,

 

    1. 点击【Build,Execution,Deployment】选项,

 

    1. 再点击【Compiler】选项,

 

    1. 勾选【Make project automatically】,

 

    点击【Apply】按钮。

自动化项目

结果 (jié guǒ)

在使用gradle bootRun启动应用后,通过刷新浏览器页面即可实时反映源代码的修改结果。

可以参考

    Configuring Spring Loaded for use with Gradle and IntelliJ