Caching the Gradle wrapper in AWS CodeBuild
Asked Answered
J

2

5

This is what my current buildspec looks like:

phases:
  build:
    commands:
      - ./gradlew soakTest -s

cache:
  paths:
    - '/root/.gradle/caches/**/*'
    - '.gradle/**/*'

But when this buildspec runs in CodeBuild, it prints messages that it is downloading gradle 4.7. It appears that other things are being cached correctly - I don't see log messages about downloading jar dependencies, for example.

What should the buildspec cache specifications look like, in order to make sure the Gradle version that the Gradle wrapper downloads gets cached?

Janejanean answered 2/5, 2018 at 3:11 Comment(0)
J
5

Add the wrapper directory to the cache paths:

- '/root/.gradle/wrapper/**/*'
Janejanean answered 5/5, 2018 at 2:37 Comment(3)
Just run into the same problem...at least for me it is not working. Problem is it seems CodeBuild with local cache will not cache recursively, but only the wrapper folder. Do you see the same?Yecies
You have to use the S3 cache. Local cache is not optimal for gradle in this situation.Allinclusive
Without enabling the S3 caching - this caches for the lifetime of the codebuild node. Codebuild will re-use machines for multiple different build invocations, if you happen to execute on the same machine that already downloaded the wrapper, it won't have to download again. This is useful at low-scale (single developer building same build repeatedly one after another ) and high-scale (large queue of builds happening concurrently with a limited pool of codebuild machines). It allows avoiding the costs and other downsides of S3 caching.Janejanean
D
0

The cache format is just a directory, no wildcards.

Just do:

cache:
  paths:
    - /root/.gradle
Disentwine answered 16/5, 2023 at 20:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.