Gradle で SNAPSHOT バージョンのライブラリを使う場合は --refresh-dependencies をつける

開発バージョンとして -SNAPSHOT を付けたものを gradle プロジェクトで利用している場合、なぜかいつまでたっても新しくアップロードした SNAPSHOT のバージョンを使ってくれない問題があった。

SNAPSHOT バージョンは下記のように maven で開発中のバージョンとして用いられるものである。

https://maven.apache.org/guides/getting-started/index.html#What_is_a_SNAPSHOT_version

https://docs.gradle.org/current/userguide/dependency_management.html#sub:cache_refresh

https://docs.gradle.org/current/userguide/dependency_management.html#sub:dynamic_versions_and_changing_modules

Alternatively, sometimes the module you request can change over time, even for the same version. An example of this type of changing module is a Maven SNAPSHOT module, which always points at the latest artifact published. In other words, a standard Maven snapshot is a module that never stands still so to speak, it is a “changing module”.

SNAPSHOT がつくバージョンは changing module と呼ばれるものらしい。

“gradle SNAPSHOT” などでググると下記のような記事が出て来る。

https://discuss.gradle.org/t/how-to-get-gradle-to-download-newer-snapshots-to-gradle-cache-when-using-an-ivy-repository/7344/2

どうやら下記のように changing modules のキャッシュ時間(デフォルト 24 時間)を調整せよとのことらしい。

https://docs.gradle.org/current/dsl/org.gradle.api.artifacts.ResolutionStrategy.html

    // don't cache changing modules at all
    cacheChangingModulesFor 0, 'seconds'

自分の環境( というか Intellij IDEA 上の gradle ?)がおかしいのか効果がなかったので おとなしく –refresh-dependencies つけることにしたことで解決した。実行に時間はかかるようになるが SNAPSHOT バージョンを使っていても新規にリポジトリに反映したバージョンを使ってくれるようになった。