0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Apollo Kotlin のバージョンアップを楽にする

Posted at

Dependabot からの PR は、いつも RED になる・・・

私のプロジェクトでは GraphQL Client として Apollo Kotlin 3.x を使っています。

GraphQL スキーマからクライアントコードを出力してくれるプラグインを使っているんですが、バージョンアップがあると以下のようにプラグインの PR、ランタイムの PR が同時にオープンして、どちらも CI が RED になっている光景を何度か目にしており、改善したいと思っていました。

image.png

なぜ RED になるかというと、エラーメッセージを見れば一目瞭然。
この 2 つはセットでバージョンアップする必要があります。
Dependabot の PR は一方の version しか書き換えていないので、どちらも同じエラーになっています。
まぁ、公式のマニュアルを工夫もせずバカ正直にコピペしてるのが悪いんですけどね・・・

CI のエラーメッセージ(抜粋)
> Task :checkApolloVersions FAILED
FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':checkApolloVersions'.
> Apollo: All apollo versions should be the same. Found:
  [3.8.0, 3.8.1]

変数で共通化する

何の変哲もない、バージョンを変数で宣言して、それを参照するやり方です。

build.gradle
buildscript {
  ext {
    apolloVersion = "3.8.0"
  }
}

plugins {
  id 'com.apollographql.apollo3' version "${apolloVersion}"
}

dependencies {
  implementation "com.apollographql.apollo3:apollo-runtime:${apolloVersion}"
}

これで Dependabot を再実行すると・・・
PR がひとつになって CI も GREEN になりました。
ちゃんと変数部分に diff が出ています。

image.png
image.png

[おまけ] Gradle 8 のバージョンカタログを使ってみる

ちょうど同じ時期に Gradle 7.2 -> 8 へのバージョンアップもやりたくて、新機能を眺めていました。
それによると、「バージョンカタログ」というものが追加されたらしく1、同じことができそうだったので試してみました。

マニュアル を見ると、バージョンの定義は settings.gradle へ書く方法と gradle/libs.versions.toml に書く方法があるようです。
今回は後者を採用してみます。

gradle/libs.versions.toml
[versions]
# 執筆時点では 3.8.1 が最新だが、dependabot の動作を検証するため意図的に古いバージョンを指定
apollo = "3.8.0"

[libraries]
apollo-runtime = { module = "com.apollographql.apollo3:apollo-runtime", version.ref = "apollo" }

[plugins]
apollo-compiler = { id = "com.apollographql.apollo3", version.ref = "apollo" }
build.gradle
plugins {
  alias(libs.plugins.apollo.compiler)
}

dependencies {
  implementation(libs.apollo.runtime)
}

apollo {
  // ...
}

これで Dependabot を再実行すると・・・
バージョンカタログを認識し、 1 つの PR で GREEN にすることができました。
ちゃんと toml ファイルに diff が出ています。
なかなか頑張ってるな Dependabot。

image.png
image.png

まとめ

Apollo Kotlin のプラグインとランタイムを同時に更新させる方法を確認しました。
buildscript の方法の方が、手っ取り早くて良いかな。

Renovate であれば PR をまとめてくれるので、もっと雑に書いてあっても上手いことしてくれるんでしょうけど・・・

  1. 正確には Gradle 7 のときから実験的な機能としてあったらしい

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?