Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle dependencies update

One of the advantages of using Gradle in Android Studio is that it helps in dependency management. So if I have used a particular version of a library in my build.gradle file, then how will I force it to update the dependency version once the higher version is available?

Some of the dependencies in my build.gradle are specified as

dependencies {
    compile project(':facebookSDK')
    compile files('libs/picasso-2.1.1.jar')
    compile files('libs/crouton-1.8.1.jar')
}
like image 534
Diffy Avatar asked Jul 25 '14 11:07

Diffy


People also ask

How do I update Gradle dependencies in eclipse?

You have to select "Refresh Dependencies" in the "Gradle" context menu that appears when you right-click the project in the Package Explorer. Show activity on this post. Show activity on this post. Show activity on this post.

How do I know if Gradle dependency has new version?

Go to Android Studio -> Preferences -> Plugins (for Mac) and File -> Settings -> Plugins (for windows) and search “Check for Dependency updates plugin”. Install it and restart android studio. You will be able to see Dependencies tab on the right which will show if any dependency has a new update available.


2 Answers

One of the advantages of using Gradle in Android Studio is that it helps in dependency management.

Not the way that you are using it.

So if i have used a particular version of a library in my build.gradle file, then how will i force it to update the dependency version once the higher version is available?

In your case, you would download the new JARs, put them in libs/, and update your build.gradle to match.

The preferred approach is for you to delete those JARs and replace your two compile files statements with ones that pull down the dependencies from Maven Central or another artifact repository. You can find the proper statements for popular open source libraries like those via the Gradle, please site.

In your case, you would use:

compile 'com.squareup.picasso:picasso:2.3.3'
compile 'de.keyboardsurfer.android.widget:crouton:1.8.5'

These will require you to also have a repositories closure as a peer to your dependencies closure:

repositories {
    mavenCentral()
}

This may already exist.

These compile statements still pin you to a specific version of those libraries, but moving to a new version would be a simple matter of updating the compile statement, and Gradle will pull down the new dependency on your next build.

If you want, you could replace part of the version number with a wildcard (e.g., 2.3.+). This will cause Gradle to automatically update to new patchlevels of the library, in this case. Some developers do not approve of this approach, as while it is convenient, it does reduce your ability to be able to reproduce a build (e.g., you need to recompile some older branch of your code, and now you don't know what version of the artifact you were using back then).

like image 90
CommonsWare Avatar answered Oct 19 '22 02:10

CommonsWare


As you are compiling files from your local project, I don't think you can automatically compile a new individual jar version if available. What you can do instead of compiling individual files is:

compile fileTree(dir: 'libs', include: '*.jar')

This will compile all jars in the libs directory so you will always have the latest version.

Both the libraries you are using are available to be compiled as dependencies from mavencentral.

compile 'de.keyboardsurfer.android.widget:crouton:1.8.5'
compile 'com.squareup.picasso:picasso:2.3.3'

If you want to ensure you are getting the latest versions is you use a plus in place of the version number. It's up to you how open you want to be with this.. so

compile 'de.keyboardsurfer.android.widget:crouton:1.+'
compile 'com.squareup.picasso:picasso:2.+'

will give you the latest version under the 1. or 2. versioning cycles...

like image 44
speedynomads Avatar answered Oct 19 '22 01:10

speedynomads