LoginSignup
21
17

More than 5 years have passed since last update.

Spring BootアプリケーションをHerokuにデプロイする

Posted at

はじめに

Spring Bootアプリケーション(Gradle使用)をHerokuにデプロイするまでの手順を整理。

手順

<初回のみの手順>

1.Herokuアカウント作成

2. Heroku Toolbeltインストール

<デプロイ対象アプリの設定>

以下を追加・変更しておく。

・build.gradle

Jettyを使用するために以下の記述を追加

build.gradle
// 先頭付近にデフォルトタスクの指定を追加
defaultTasks "clean", "build"

- 中略 -

// dependenciesに追加
compile("org.springframework.boot:spring-boot-starter-jetty")
・Procfile

JARファイルから起動するための指定

Procfile
web: java -jar build/libs/xxxx-0.0.1-SNAPSHOT.jar --server.port=$PORT (注:xxxxはjarのbaseName)
・system.properties

Javaのバージョンを指定

system.properties
java.runtime.version=1.8
・.gitignore

不要なファイルをコミットしないように、コミット対象外のものを記述
(gradle wrapperはHeroku上のビルドに必要なので/gradleは記述しないように注意)

.gitignore(例)
.apt_generated
.gradle
.settings
bin
build
lib
log
temp
.classpath
.DS_Store
.factorypath
.project
gradlew.bat

<新規デプロイ時の手順>

1. ソースをGitに保存

ターミナル
cd xxxx (注:xxxxはアプリのルートフォルダ)
git init
git add .
git commit -m "init" (注:任意のコミットメッセージ)

2. Herokuにログイン

ターミナル
heroku login

3. Herokuアプリを作成

ターミナル
heroku create xxxx (注:xxxxは任意のアプリ名)

4. Herokuでgradle wrapperを利用できるように設定

ターミナル
heroku config:set BUILDPACK_URL=https://github.com/marcoVermeulen/heroku-buildpack-gradlew.git --app xxxx (注:xxxxはアプリ名)

5. Herokuにデプロイ

ターミナル
git push heroku master

参考

21
17
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
21
17