Home > Software engineering >  Why would I use $version instead of '2.7.0'?
Why would I use $version instead of '2.7.0'?

Time:01-30

I would like to understand the practise of not putting the version codes in your dependencies.

Why would I choose one practise over the other:

dependencies {
   implementation "com.squareup.retrofit2:retrofit:$retrofit_version"
   implementation "com.squareup.retrofit2:converter-moshi:$moshi_version"
   implementation "com.squareup.okhttp3:okhttp:$okhttp_version"
 } 

vs

 dependencies {
   implementation "com.squareup.retrofit2:retrofit:2.9.0"
   implementation "com.squareup.retrofit2:converter-moshi:2.9.0"
   implementation "com.squareup.okhttp3:okhttp:4.9.0"
 }

CodePudding user response:

Simply because it may be that the version is important for several dependencies. For example, like here:

implementation "androidx.navigation:navigation-runtime-ktx:$navigation_version"
implementation "androidx.navigation:navigation-fragment-ktx:$navigation_version"
implementation "androidx.navigation:navigation-ui-ktx:$navigation_version"

So you only need to adjust the version once and don't run the risk of forgetting a change.

  • Related