How to update Gradle dependencies to their latest version

前端 未结 4 927
有刺的猬
有刺的猬 2020-12-24 06:02

Is there an easy way to get gradle to update dependencies to their latest available version?

For build reproducibility all my dependencies are defined with a version

相关标签:
4条回答
  • 2020-12-24 06:33

    I suffer from it, too. And the best way to check dependencies, even manually, is to go through Project Structure and search for the dependency name and see if there is a newer version.

    The problem that this query only checks for the dependencies present in the Maven repository. At least it already goes for Google's.

    Note: If you choose to add the dependency with the new version, this will add a duplicity in the your App Gradle, so be sure to delete the old dependency row.

    #

    Another possible quick fix is through the command line:

    ./gradlew app: dependencies
    

    This will generate an output like the one below. Note that the asterisk points to a possible new existing version.

    0 讨论(0)
  • 2020-12-24 06:35

    This is all I've been able to come up with. I will happily accept another answer if there is a less manual method of doing this.

    1. In Android studio I replace every dependency version with a plus example: compile 'namespace:package1:+'

    2. Sync or build the project which will cause all the dependencies to be resolved to their latest version.

    3. In Android Studio place the cursor on each dependency line in build.gradle and press alt+enter a menu pops up and you can select Replace with specific version

    0 讨论(0)
  • 2020-12-24 06:35

    Add to build.gradle:

    plugins {
      id 'com.github.ben-manes.versions' version '0.17.0'
    }
    

    Then you can do gradle dependencyUpdates to get a report of new versions. Unlike the eponymous Maven plugin, there doesn't seem to be a way of automatically updating the build.gradle yet.

    More documentation: https://github.com/ben-manes/gradle-versions-plugin

    0 讨论(0)
  • 2020-12-24 06:58

    It is not a really good practice as libraries can include changes that may break your code.

    A common "tolerated" syntax for

    compile 'namespace:package:major_version.minor_version.revision'
    

    would be like

    compile 'namespace:package:1.0.+'
    

    considering revision is used by the library authors as bug fixes and improvements updates

    Note: I just did that and you could do

    compile 'namespace:package:+'
    

    Edit:
    A Proof Of Concept of my latest comment you may want to test.
    This was made in 5 minutes, so don't expect it to be perfect nor flexible.

    0 讨论(0)
提交回复
热议问题