LoginSignup
43
44

More than 5 years have passed since last update.

Spring Boot + Gradle + IntelliJ IDEAの環境に + Spring Loaded

Last updated at Posted at 2014-11-29

目的

Spring Boot、Gradle、Intellij IDEAの環境は開発しやすいが実行結果を確認する場合に何度もgradle bootRunを叩いて再起動する必要がある。

そこでSpring Loadedを導入して一度gradle bootRunでアプリを起動させることで、ソースの変更結果をgradle bootRunを何度も叩かず反映させられるようにする。

環境

  • Gradle 2.1
  • intelliJ IDEA 14
  • Spring Boot 1.1.9
  • Spring loaded 1.2.1

手順

1. build.gradle作成

以下がテンプレート

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ブロックの設定はIntelliJ IDEAがコンパイルしたファイル群を配置する先をGradleがコンパイルしたファイルを配置する先に合わせるための記述。

2. IntelliJ IDEAの自動コンパイル設定

筆者のIntelliJ IDEAはデフォルトで自動コンパイルとなっていなかった。
(デフォルトでコンパイルされないのか、過去に設定を変えたのか覚えていない…)

自動コンパイルを有効化させる。

自動コンパイル有効化手順

  1. ⌘.でPreferencesを開く
  2. Build,Execution,Deployment -> Compiler を開く
  3. Make project automaticallyをチェック
  4. Applyをクリック

検索キーワード:Make project automatically

結果

gradle bootRunでアプリ実行後に変更を加えたソースはブラウザの画面をリロードすることで、ソースの変更結果が反映される。

参考

43
44
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
43
44