Android Studio: Snapshot Dependencies Don't Up

2020-06-09 07:00发布

问题:

I'm working With Android Studio 8.9

I've got a build.gradle with the following dependency defined:

compile ('my.program.commons:my-program-commons:0.0.2-SNAPSHOT@jar')

This dependency is stored in a private Sonatype nexus repository.

When I make changes in the my.program.commons code, I upload to nexus.

The problem is that when I then try to compile against the new SNAPSHOT android studio will fail to pick up changes.

When run from the command line gradle will build succesfully - but Android Studio will not recognize the new files.

If i do a version tick - say from 0.0.2-SNAPSHOT to 0.0.3-SNAPSHOT Android Studio will understand the new version and download and everything works out fine.

I don't want to have to do a minor version tick on every single change.

回答1:

You need to configure the cache duration, by default gradle won't look for updates for 24 hours:

http://www.gradle.org/docs/current/userguide/dependency_management.html#sec:controlling_caching



回答2:

In my case, use changing = true not work for me. But configure cache changing modules solve my problem. Sample code below, add in build.gradle file:

configurations.all {
    // Don't cache changing modules at all.
    resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
}

See: https://docs.gradle.org/current/userguide/dependency_management.html



回答3:

You can also put a flag called "changing" that will trigger Gradle to always pull the latest, for example:

compile ('my.program.commons:my-program-commons:0.0.2-SNAPSHOT@jar') {
 changing = true;
}


回答4:

In my case, removing the whole <project_root>/.idea/libraries directory, was the only solution that worked. AndroidStudio stores some cached dependencies configurations there. Removing the directory makes it refetch all of them one more time.

You can write some script/task that will automate this removal and run it as part of the Gradle clean task.