How to migrate an existing project to refreshVersions
See original GitHub issue- Status: I wrote the documentation of the migration process as I imagine it.
- Implementation: I have a draft implementation of
./gradlew refreshVersions --show missing-versions
in the branch poc-all-versions
refreshVersions migration
As described in Adding Dependencies, refreshVersions has an opt-in mechanism. It only manages dependencies that were declared with a version placeholder _
dependencies {
implementation("com.squareup.okhttp3:okhttp:_") // OK, managed
implementation("com.squareup.moshi:moshi:1.9.3") // Harcoded, not managed
}
The chicken and egg problem
If you migrate an existing project, all dependencies versions will be hardcoded, so refreshVersions will manage nothing
## versions.properties
# no version whatsoever here :'(
So how do you migrate?
You could replace directly all hardcoded versions with the placeholder
// build.gradle
dependencies {
implementation("com.squareup.okhttp3:okhttp:_")
- implementation("com.squareup.moshi:moshi:1.9.3")
+ implementation("com.squareup.moshi:moshi:_")
}
Sync Gradle.
You will then notice an unwanted side-effect:
## versions.properties
+version.moshi=1.11.0
That’s not good, moshi was silently updated to the latest available version instead of the one that the build was using 🤨
So here is what you do instead
Add missing versions
Run the following command
$ ./gradlew refreshVersions --show missing-versions
> Task refreshVersions
Following versions are currently missing in versions.properties:
version.okhttp=4.8.3
version.moshi=1.11.0
Use the output of this command to modify manually versions.properties
## versions.properties
+version.okhttp=4.8.3
+version.moshi=1.11.0
Replace hardcoded dependencies versions
The next step is to find and replace all hardcoded versions with the placeholder _
.
Depending on the size of the project, this could be simple or a bit tricky.
Fortunately, we have another command that will guide you in this process
$ ./gradlew refreshVersions --show harcoded-versions
> Task refreshVersions
Searching for hardcoded versions...
# core/build.gradle
Found 1 hardcoded dependency:
moshi
# app/build.gradle.kts
Found 3 harcoded dependencies:
cardview constraintlayout picaso
Search those dependencies and replace the hardcoded version with _
// core/build.gradle
- implementation 'com.squareup.moshi:moshi:1.9.3'
+ implementation 'com.squareup.moshi:moshi:_'
// app/build.gradle.kts
- implementation("com.squareup.moshi:moshi:1.9.3")
- implementation("androidx.constraintlayout:constraintlayout:1.2.0")
- implementation("com.squareup.picasso:picaso:1.0.0")
+ implementation("com.squareup.moshi:moshi:_")
+ implementation("androidx.constraintlayout:constraintlayout:_")
+ implementation("com.squareup.picasso:picaso:_")
Check again that you have no hard-coded version
$ ./gradlew refreshVersions --show harcoded-versions
> Task refreshVersions
Searching for hardcoded versions...
# core/build.gradle
No harcoded version
# app/build.gradle.kts
No harcoded version
Commit your changes
Run $ ./gradlew refreshVersions
At that point, your project is setup correctly. You have the same versions as before but can now lookup for available updates
$ ./gradlew refreshVersions
$ cat versions.properties
## versions.properties
version.okhttp=4.8.3
## # available=4.9.0
version.moshi=1.11.0
## #available=1.13.0
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (1 by maintainers)
Top GitHub Comments
We can do better (though we have great ideas and a clear explanation of the problem).
Please let me comment more in depth this weekend. I’ll prioritize this over reviewing the website updates.
From my experience the best migration can be done with Regex and Find&Replace.
\${Versions\.[A-Za-z]*}
worked well