Need a Gradle task to copy ALL dependencies to a local maven repo

For anyone reading this who just wants to get the jar/pom files of the gradle cache into his local maven repo, you can simply use this gradle task:

task cacheToMavenLocal(type: Copy) {
  from new File(gradle.gradleUserHomeDir, 'caches/modules-2/files-2.1')
  into repositories.mavenLocal().url
  eachFile {
    List<String> parts = it.path.split('/')
    it.path = (parts[0]+ '/' + parts[1]).replace('.','/') + '/' + parts[2] + '/' + parts[4]
  }
  includeEmptyDirs false
}

Note that this can take a long time if you have a big cache.

5 Likes