Gradle Wrapperのバージョンアップ手順

たまにしかやらないので忘れがちなGradle Wrapperのバージョンアップ手順のメモです。

手順

まずバージョンアップ前。

$ ./gradlew -v

------------------------------------------------------------
Gradle 5.2.1
------------------------------------------------------------
以下省略

wrapperタスクの--gradle-versionオプションで変更後のバージョンを指定します。

$ ./gradlew wrapper --gradle-version 5.4

BUILD SUCCESSFUL in 1s
1 actionable task: 1 executed

これだけだと設定が書き換わっただけでローカルのgradlewはまだ変更前のバージョンのままです。

$ git diff
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
index 44e7c4d..5f1b120 100644
--- a/gradle/wrapper/gradle-wrapper.properties
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -1,5 +1,5 @@
 distributionBase=GRADLE_USER_HOME
 distributionPath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-5.2.1-bin.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-5.4-bin.zip
 zipStoreBase=GRADLE_USER_HOME
 zipStorePath=wrapper/dists

何かしらのタスクを実行すると設定したバージョンが反映されるのでwrapperタスクを実行します。

$ ./gradlew wrapper
Downloading https://services.gradle.org/distributions/gradle-5.4-bin.zip
...................................................................................

Welcome to Gradle 5.4!

Here are the highlights of this release:
 - Run builds with JDK12
 - New API for Incremental Tasks
 - Updates to native projects, including Swift 5 support

For more details see https://docs.gradle.org/5.4/release-notes.html

Starting a Gradle Daemon (subsequent builds will be faster)

BUILD SUCCESSFUL in 15s
1 actionable task: 1 executed

gradle-wrapper.properties以外も変更されています。

$ git status
On branch master
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

        modified:   gradle/wrapper/gradle-wrapper.jar
        modified:   gradle/wrapper/gradle-wrapper.properties
        modified:   gradlew
        modified:   gradlew.bat

no changes added to commit (use "git add" and/or "git commit -a")

参考リンク