kdnakt blog

hello there.

HomebrewでGradleをバージョンアップした(6.7.1 -> 7.0.2)

最近Gradleを色々触っている。そういえば新しいバージョン(7.X)がリリースされたはず、と思い更新してみた。

 

gradle.org

 

  

[Gradleのバージョンが古い]

更新前は以下のバージョンを利用していた。

$ gradle -v

------------------------------------------------------------
Gradle 6.7.1
------------------------------------------------------------

Build time:   2020-11-16 17:09:24 UTC
Revision:     2972ff02f3210d2ceed2f1ea880f026acfbab5c0

Kotlin:       1.3.72
Groovy:       2.5.12
Ant:          Apache Ant(TM) version 1.10.8 compiled on May 10 2020
JVM:          15.0.1 (Oracle Corporation 15.0.1+9)
OS:           Mac OS X 10.15.7 x86_64

 

[brew upgrade失敗]

brewでパッケージを更新するときはbrew upgrade <パッケージ>と覚えていたので、実行してみた。

すると、エラーとすでにバージョン6.7.1がインストールされていると警告メッセージが表示された。

$ brew upgrade gradle
Error: 
  homebrew-core is a shallow clone.
  homebrew-cask is a shallow clone.
To `brew update`, first run:
  git -C /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core fetch --unshallow
  git -C /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask fetch --unshallow
This restriction has been made on GitHub's request because updating shallow
clones is an extremely expensive operation due to the tree layout and traffic of
Homebrew/homebrew-core and Homebrew/homebrew-cask. We don't do this for you
automatically to avoid repeatedly performing an expensive unshallow operation in
CI systems (which should instead be fixed to not use shallow clones). Sorry for
the inconvenience!
Warning: gradle 6.7.1 already installed

  

エラーはともかく、2021年6月現在、Gradleの最新バージョンは7.Xのはずでは、と思い、Homebrewのサイトを確認すると、7.0.2が最新だと表示されている。

 

formulae.brew.sh

 

なんとか最新のGradleをインストールする方法はないかと思い、homebrew install latest versionで検索すると、以下のページがヒットした。

stackoverflow.com

 

まずはHomebrewそのものを更新する必要があるらしい。

というわけで、コマンドを調べると、brew updateでHomebrewを更新できそうだったので実行してみた。

f:id:kidani_a:20210605190447p:plain

結局gradleを更新しようとしたときと、同じエラーが表示された。

調べてみると、どうやらやり方が変わったということらしい。

gotohayato.com

 

実際に表示されていたコマンド2つを実行してみる。

$ git -C /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core fetch --unshallow
remote: Enumerating objects: 550402, done.
remote: Counting objects: 100% (550364/550364), done.
remote: Compressing objects: 100% (199520/199520), done.
remote: Total 541084 (delta 349915), reused 529777 (delta 338735), pack-reused 0
Receiving objects: 100% (541084/541084), 192.32 MiB | 8.29 MiB/s, done.
Resolving deltas: 100% (349915/349915), completed with 8191 local objects.
From https://github.com/Homebrew/homebrew-core
   0aae21fd18..c70c385dec  master     -> origin/master

$ git -C /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask fetch --unshallow
remote: Enumerating objects: 440985, done.
remote: Counting objects: 100% (440960/440960), done.
remote: Compressing objects: 100% (129872/129872), done.
remote: Total 433954 (delta 310683), reused 426710 (delta 303506), pack-reused 0
Receiving objects: 100% (433954/433954), 193.16 MiB | 7.76 MiB/s, done.
Resolving deltas: 100% (310683/310683), completed with 5586 local objects.
From https://github.com/Homebrew/homebrew-cask
   4ee4b20e66..29d0a3dc67  master     -> origin/master

 

それぞれ数分ずつ時間がかかった。

これでようやくHomebrewを更新できる。

$ brew update
Updated Homebrew from 3e53d5ba7 to 654c78c2d.
Updated 4 taps (homebrew/cask-versions, homebrew/core, homebrew/cask and homebrew/bundle).
==> New Formulae
// 略
==> Updated Formulae
// 略
==> Renamed Formulae
// 略 
==> Deleted Formulae
// 略 
==> New Casks
// 略 
==> Updated Casks
// 略 
==> Deleted Casks
// 略 
You have 37 outdated formulae and 3 outdated casks installed.
You can upgrade them with brew upgrade
or list them with brew outdated.

==> Homebrew was updated to version 3.1.9
The changelog can be found at:
  https://github.com/Homebrew/brew/releases/tag/3.1.9

 

Homebrewは2021年6月時点で最新の3.1.9に更新されたが、この時点ではgradleは更新されていなかった。

 

[いざbrew upgrade gradle]

いよいよGradleを更新する。

$ brew upgrade gradle
==> Upgrading 1 outdated package:
gradle 6.7.1 -> 7.0.2_2
==> Upgrading gradle 6.7.1 -> 7.0.2_2 
==> Downloading https://ghcr.io/v2/homebrew/core/openjdk/manifests/16.0.1
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/openjdk/blobs/sha256:04435cc60a4cdf18dade6923a8a039
==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sha256:04435cc60a4cdf1
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/gradle/manifests/7.0.2_2
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/gradle/blobs/sha256:e6fe8586f00011efce1876ac2e6a9f4
==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sha256:e6fe8586f00011e
######################################################################## 100.0%
==> Installing dependencies for gradle: openjdk
==> Installing gradle dependency: openjdk
==> Pouring openjdk--16.0.1.catalina.bottle.tar.gz
🍺  /usr/local/Cellar/openjdk/16.0.1: 617 files, 330.2MB
==> Installing gradle
==> Pouring gradle--7.0.2_2.catalina.bottle.tar.gz
🍺  /usr/local/Cellar/gradle/7.0.2_2: 10,864 files, 260.6MB
Removing: /usr/local/Cellar/gradle/6.7.1... (11,049 files, 251.9MB)
Removing: /Users/XXXXX/Library/Caches/Homebrew/gradle--6.7.1.zip... (139.5MB)
==> Upgrading 2 dependents:
kotlin 1.4.21 -> 1.5.10, maven 3.6.3_1 -> 3.8.1
==> Upgrading kotlin 1.4.21 -> 1.5.10 
==> Downloading https://ghcr.io/v2/homebrew/core/kotlin/manifests/1.5.10
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/kotlin/blobs/sha256:f36c4c6324165ae872d237d9a0f720e
==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sha256:f36c4c6324165ae
######################################################################## 100.0%
==> Pouring kotlin--1.5.10.all.bottle.tar.gz
🍺  /usr/local/Cellar/kotlin/1.5.10: 107 files, 64.5MB
Removing: /usr/local/Cellar/kotlin/1.4.21... (108 files, 64.5MB)
Removing: /Users/XXXXX/Library/Caches/Homebrew/kotlin--1.4.21.zip... (58.0MB)
==> Upgrading maven 3.6.3_1 -> 3.8.1 
==> Downloading https://www.apache.org/dyn/closer.lua?path=maven/maven-3/3.8.1/binaries/apache-maven
==> Downloading from https://downloads.apache.org/maven/maven-3/3.8.1/binaries/apache-maven-3.8.1-bi
######################################################################## 100.0%
🍺  /usr/local/Cellar/maven/3.8.1: 87 files, 10.8MB, built in 5 seconds
Removing: /usr/local/Cellar/maven/3.6.3_1... (87 files, 10.7MB)
Removing: /Users/XXXXX/Library/Caches/Homebrew/maven--3.6.3.tar.gz... (9MB)
==> Checking for dependents of upgraded formulae...
==> No broken dependents found!

 

 

無事にGradleが更新された!念のためバージョンを確認しておく。

$ gradle -v

Welcome to Gradle 7.0.2!

Here are the highlights of this release:
 - File system watching enabled by default
 - Support for running with and building Java 16 projects
 - Native support for Apple Silicon processors
 - Dependency catalog feature preview

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


------------------------------------------------------------
Gradle 7.0.2
------------------------------------------------------------

Build time:   2021-05-14 12:02:31 UTC
Revision:     1ef1b260d39daacbf9357f9d8594a8a743e2152e

Kotlin:       1.4.31
Groovy:       3.0.7
Ant:          Apache Ant(TM) version 1.10.9 compiled on September 27 2020
JVM:          16.0.1 (Homebrew 16.0.1+0)
OS:           Mac OS X 10.15.7 x86_64

 

きちんと最新バージョンのGradle7.0.2がインストールされた。

 

[まとめ]

  • 2020年以前のHomebrewを使っている場合は、brew update実行前にGitリポジトリの更新が必要
  • brew updateに成功してからでないと、Homebrewで管理しているパッケージを更新できない
  • Gradleパッケージを更新するときはbrew upgrade gradleを実行する