sbt dependency updatesでScalaプロジェクトの依存ライブラリの更新をチェックする

sbt dependency updates プラグインでプロジェクトライブラリのバージョン更新をチェックしてみました。
2021.01.26

この記事は公開されてから1年以上経過しています。情報が古い可能性がありますので、ご注意ください。

はじめに

Scalaのプロジェクトを長い間メンテナンスしていると使用しているライブラリの数が多くなり、その更新にキャッチアップするのだけで大変な手間がかかります。

今回は長いことメンテナンスしていなかったslack botのプロジェクトにsbt dependency updatesプラグインを導入してライブラリのアップデートをしてみました。

インストール

project/plugins.sbt に以下を追記します。

addSbtPlugin("org.jmotor.sbt" % "sbt-dependency-updates" % "1.2.2")

実行

sbt shellからdependencyUpdates を実行すると以下のようにパッケージの更新情報が表示されます。インストール先に応じてセクションが分かれて表示されます。

チェックマークがついているライブラリは最新版を使用していて、より新しいバージョンが存在するライブラリは最新バージョンが表示されています。

org.scala-lang:scala-library:2.12.8 ---> 2.13.4 とScalaのバージョンもチェックされていますね。

[info] Done checking.
                                         facilitator-rotate-bot                                          
[info] ---------------------------------- Global Plugins ----------------------------------
[unreleased] net.virtual-void:sbt-dependency-graph:0.10.0-RC1 ---> 0.9.2 
[not_found ] org.jetbrains:sbt-idea-shell:2017.2 × 
[info] -------------------------------------  Plugins -------------------------------------
[success   ] com.eed3si9n:sbt-assembly:0.14.10 √ 
[expired   ] org.wartremover:sbt-wartremover:2.4.3 ---> 2.4.13 
[expired   ] org.scalameta:sbt-scalafmt:2.2.0 ---> 2.4.2 
[expired   ] org.jmotor.sbt:sbt-dependency-updates:1.2.1 ---> 1.2.2 
[not_found ] org.lyranthe.sbt:partial-unification:1.1.2 × 
[not_found ] com.github.cb372:sbt-explicit-dependencies:0.2.16 × 
[info] ----------------------------------- Dependencies -----------------------------------
[success   ] ch.qos.logback:logback-classic:1.2.3 √ 
[success   ] com.typesafe.scala-logging:scala-logging:3.9.2 √ 
[success   ] org.scalamacros:paradise:2.1.1 √ 
[expired   ] org.scala-lang:scala-library:2.12.8 ---> 2.13.4 
[expired   ] org.wartremover:wartremover:2.4.3 ---> 2.4.13 
[expired   ] io.circe:circe-core:0.11.1 ---> 0.13.0 
[expired   ] io.circe:circe-generic:0.11.1 ---> 0.13.0 
[expired   ] io.circe:circe-parser:0.11.1 ---> 0.13.0 
[expired   ] io.monix:monix-eval:3.0.0 ---> 3.3.0 
[expired   ] com.github.j5ik2o:reactive-aws-dynamodb-core:1.1.0 ---> 1.2.6 
[expired   ] com.github.j5ik2o:reactive-aws-dynamodb-cats:1.1.0 ---> 1.2.6 
[expired   ] com.github.pureconfig:pureconfig:0.12.1 ---> 0.14.0 
[expired   ] net.logstash.logback:logstash-logback-encoder:5.3 ---> 6.6 
[expired   ] com.fasterxml.jackson.module:jackson-module-scala:2.9.8 ---> 2.12.1 
[expired   ] com.slack.api:bolt-aws-lambda:1.0.1 ---> 1.6.1 
[success] Total time: 3 s, completed 2021/02/17 21:16:12
[IJ]

バージョン修正後

古くなっていたライブラリのバージョンをbuild.sbt内で更新後に再度実行すると以下のようにチェックマークが増え、最新のバージョンを指定していることがわかります。

facilitator-rotate-bot                                          
[info] ---------------------------------- Global Plugins ----------------------------------
[unreleased] net.virtual-void:sbt-dependency-graph:0.10.0-RC1 ---> 0.9.2 
[not_found ] org.jetbrains:sbt-idea-shell:2017.2 × 
[info] -------------------------------------  Plugins -------------------------------------
[success   ] org.wartremover:sbt-wartremover:2.4.13 √ 
[success   ] org.scalameta:sbt-scalafmt:2.4.2 √ 
[success   ] com.eed3si9n:sbt-assembly:0.14.10 √ 
[success   ] org.jmotor.sbt:sbt-dependency-updates:1.2.2 √ 
[not_found ] org.lyranthe.sbt:partial-unification:1.1.2 × 
[not_found ] com.github.cb372:sbt-explicit-dependencies:0.2.16 × 
[info] ----------------------------------- Dependencies -----------------------------------
[success   ] org.wartremover:wartremover:2.4.13 √ 
[success   ] io.circe:circe-core:0.13.0 √ 
[success   ] io.circe:circe-generic:0.13.0 √ 
[success   ] io.circe:circe-parser:0.13.0 √ 
[success   ] ch.qos.logback:logback-classic:1.2.3 √ 
[success   ] com.typesafe.scala-logging:scala-logging:3.9.2 √ 
[success   ] io.monix:monix-eval:3.3.0 √ 
[success   ] com.github.j5ik2o:reactive-aws-dynamodb-core:1.2.6 √ 
[success   ] com.github.j5ik2o:reactive-aws-dynamodb-cats:1.2.6 √ 
[success   ] net.logstash.logback:logstash-logback-encoder:6.6 √ 
[success   ] com.github.pureconfig:pureconfig:0.14.0 √ 
[success   ] com.fasterxml.jackson.module:jackson-module-scala:2.12.1 √ 
[success   ] com.slack.api:bolt-aws-lambda:1.6.1 √ 
[success   ] org.scalamacros:paradise:2.1.1 √ 
[expired   ] org.scala-lang:scala-library:2.12.8 ---> 2.13.4 
[success] Total time: 3 s, completed 2021/02/17 21:22:23
[IJ]

まとめ

sbt dependency updates プラグインでプロジェクトライブラリのバージョン更新をチェックしてみました。設定もさほど必要ないのでbreaking changeの対応にしっかり時間を使えますね。