question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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:closed
  • Created 3 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
LouisCADcommented, Oct 16, 2020

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.

0reactions
THEAccesscommented, Apr 3, 2021

From my experience the best migration can be done with Regex and Find&Replace. \${Versions\.[A-Za-z]*} worked well

Read more comments on GitHub >

github_iconTop Results From Across the Web

Migrate - gradle refreshVersions
Migrating an existing project to refreshVersions manually is tricky: Existing dependencies are ignored because they don't use the version placeholder _ .
Read more >
How to migrate an existing project to refreshVersions - - Bountysource
refreshVersions migration · The chicken and egg problem · Add missing versions · Replace hardcoded dependencies versions · Run $ ./gradlew refreshVersions.
Read more >
jmfayard/refreshVersions: Life is too short to google ... - GitHub
The refreshVersionsMigrate task can help you migrate your project in a few minutes, or less. In version 0.50.0, support for Gradle's Versions Catalogs...
Read more >
Update your Gradle dependencies in 10 seconds ... - pgreze
Auto-update your dependencies. If you could finally migrate your project, just execute the following Gradle command: ./gradlew refreshVersions.
Read more >
Keeping Gradle Dependencies up to Date with GitHub Actions ...
How to use GitHub Actions to semi-automate dependency updates using RefreshVersions.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found