1

Given I have multiple agents which build Gradle 5.X based applications, I'd like to start caching Gradle dependencies across all agents.

I tried to share .gradle folder, but when I try to run the same build on 2 agents, one of them fails on:

Caused by: org.gradle.api.UncheckedIOException: 

Failed to create parent directory '/home/buildagent/.gradle/caches/5.0' 

when creating directory '/home/buildagent/.gradle/caches/5.0/generated-gradle-jars'

How can I share dependencies across Teamcity agents?

Is there a generic solution which will support Gradle 5 onwards?

I found this in Gradle 6.x documentation, but I didn't find anything in 5.x documentation.

Patrik Mihalčin
  • 3,341
  • 7
  • 33
  • 68

1 Answers1

0

I cannot say what the root cause of the exception you get is, since the message is quite sparse. All I can say is that for Gradle 5 there is no built-in solution to share the local cache via network as you would like to do. The ability to copy and reuse the cache you mentioned has been introduced with Gradle 6.1 and has some limitations:

  • It is primarily meant to copy contents to other machines, possibly with different directory structures (cache relocation).
  • Supports the module cache ($GRADLE_HOME/caches/modules-<version>) only
  • Network shares most likely only work as read-only dependency cache.

So, what's a portable solution that works for Gradle 5 and 6? According to the ticket that originally introduced the cache reusability (Make dependency caches relocateable #1338):

  1. Copy, not network mount, the folder. Directory structure must remain consistent across different machines.
  2. Mount a previously exported repository with your dependencies:

    Write a Gradle task that creates a file repository from your dependencies and package that file repository. Then have logic in your build that says "if that file repository is present, use it".

    (From this comment)

thokuest
  • 5,800
  • 24
  • 36