Force refresh of archive
Force refresh of archive
My project has a dependency on an .aar
file located remotely.
.aar
Android Studio
keeps a copy of this file in my ./gradle/caches
directory
Android Studio
./gradle/caches
When I clean and re-build the project, the file is not refreshed.
How can I force Android Studio
to reload the archive from the remote location ?
Android Studio
Or is it possible to disable the gradle
cache for a specific file ?
gradle
EDIT: I'd like to force a refresh of a specific file, not of the whole cache => This question is not a duplicate of How to clear gradle cache?
I read that already, it takes too long to clear and rebuild the whole cache, hence my question
– matdev
Jan 2 '18 at 11:32
1 Answer
1
You can disable caching in ~/.gradle/gradle.properties
:
~/.gradle/gradle.properties
org.gradle.caching=false
Also you can define a task to do that :
task('clearDomainCache', type: Delete, group: 'Utilities',
description: "Deletes any cached artifacts with the domain of com.myCompany in the Gradle or Maven2 cache directories.") doLast
def props = project.properties
def userHome = System.getProperty('user.home')
def domain = props['domain'] ?: 'com.myCompany'
def slashyDomain = domain.replaceAll(/./, '/')
file("$userHome/.gradle/cache").eachFile ^resolved-$domain") delete cacheFile.path
if (cacheFile.name =~ "^*.aar") delete cacheFile.path
delete "$userHome/.m2/repository/$slashyDomain"
I've added org.gradle.caching=false to my gradle.properties file and when I build, an old version of the archive reappears in my .gradle directory :(
– matdev
Jan 2 '18 at 15:12
I've tried using a task, but running it does not delete the classes.jar file contained in my .gradle/caches/transforms-1/files-1.1/ directory. Also, even with org.gradle.caching=false, the archive file keep on, reappearing in .gradle/caches
– matdev
Jan 9 '18 at 9:54
this statement control delete process
if (cacheFile.name =~ "^$domain|^resolved-$domain")
@matdev– Arash Hatami
Jan 19 '18 at 11:04
if (cacheFile.name =~ "^$domain|^resolved-$domain")
Many thanks ! I managed to clear the cached aar files by adding the line if (cacheFile.name =~ "^*.aar") delete cacheFile.path
– matdev
Jan 22 '18 at 9:48
OK that sounds good ... answer updated @matdev
– Arash Hatami
Jan 22 '18 at 9:54
Thanks for contributing an answer to Stack Overflow!
But avoid …
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
But avoid …
To learn more, see our tips on writing great answers.
Required, but never shown
Required, but never shown
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Possible duplicate of How to clear gradle cache?
– Arash Hatami
Jan 2 '18 at 10:38