Why does Gradle re-run up-to-date tests on GitLab CI when I am caching the build directory?
Asked Answered
A

1

7

I have the following build configuration for a multi-project gradle file:

stages:
  - test

before_script:
  - export GRADLE_USER_HOME=`pwd`/.gradle

cache:
  paths:
    - .gradle/wrapper
    - .gradle/caches
    - build

test :
  dependencies: []
  image: openjdk:x
  stage: test
  script:
      - ./gradlew test --debug

On the GitLab, between builds with no changes to source files, I get:

Up-to-date check for task ':x:compileJava' took 1.117 secs. It is not up-to-date because:
No history is available.

I'm not sure why it says this, as I would expected the task history to be restored from cache. I see this in the logs between runs:

Creating cache default...
.gradle/wrapper: found 207 matching files          
.gradle/caches: found 5058 matching files          
build: found 2743 matching files

When I re-run on my local machine, I can see the tests are not being re-run:

> Skipping task ':x:compileJava' as it is up-to-date (took 0.008 secs).

More confusing is dependencies are cached perfectly, it just keeps rerunning tests when I have made no code changes.

Alcinia answered 23/12, 2017 at 14:49 Comment(2)
Did you ever find a solution to this? I am facing the same issueSontich
Never found a solution unfortunately.Alcinia
J
1

As far as I know the history that gradle is missing is also stored in the .gradle folder, but not in the caches or wrapper subfolder. If you tell Gitlab to cache the complete .gradle folder the problem should go away.

See also this example: https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/ci/templates/Gradle.gitlab-ci.yml

Junto answered 16/2, 2023 at 15:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.