强制刷新存档

时间:2018-01-02 10:36:24

标签: android-studio gradle android-gradle

我的项目依赖于远程定位的.aar文件。

Android Studio会在./gradle/caches目录

中保留此文件的副本

当我清理并重新构建项目时,文件不会刷新。

如何强制Android Studio从远程位置重新加载存档?

或者是否可以禁用特定文件的gradle缓存?

编辑:我想强制刷新特定文件,而不是刷新整个缓存=>此问题与How to clear gradle cache?

不重复

1 个答案:

答案 0 :(得分:3)

您可以在~/.gradle/gradle.properties中禁用缓存:

org.gradle.caching=false

您也可以定义一项任务:

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 { cacheFile ->
      if (cacheFile.name =~ "^$domain|^resolved-$domain") delete cacheFile.path
      if (cacheFile.name =~ "^*.aar") delete cacheFile.path
   }
   delete "${userHome}/.m2/repository/$slashyDomain"
}