How to speed up gradle daemon in CI pipeline

Describe your question in as much detail as possible:

We’re building Spring Boot Kotlin apps using Gradle Kotlin. Gradle startup times are slow.

  • What are you seeing, and how does that differ from what you expect to see?

We are seeing gradle daemon start times approaching 3 minutes (see below). Modern versions of gradle do not allow you to disable the daemon. We would like to see these perform better, as we are paying for CI minutes.

$ time gradle --daemone[0;m
Starting a Gradle Daemon (subsequent builds will be faster)

> Task :help

Welcome to Gradle 8.0.2.

To run a build, run gradle <task> ...

To see a list of available tasks, run gradle tasks

To see more detail about a task, run gradle help --task <task>

To see a list of command-line options, run gradle --help

For more detail on using Gradle, see https://docs.gradle.org/8.0.2/userguide/command_line_interface.html

For troubleshooting, visit https://help.gradle.org

BUILD SUCCESSFUL in 2m 42s
1 actionable task: 1 executed

real	2m43.055s
user	0m2.185s
sys	0m0.221s
  • What version are you on? Are you using self-managed or GitLab.com?

We are on gitlab.com SaaS. Latest version as of this writing.

  • Add the CI configuration from .gitlab-ci.yml and other configuration if relevant (e.g. docker-compose.yml)
build-artifacts:
  stage: build-artifacts
  services:
    - name: postgres:14.2
      alias: postgres-cicd
    - name: mongo:4.4
      alias: mongo-cicd
    - name: redis:7.0.4-alpine
      alias: redis-cicd
    - name: orientdb:3.2.17
      alias: orientdb-cicd
    # the following images require DOCKER_AUTH_CONFIG to be properly set;
    # see https://docs.gitlab.com/ee/ci/docker/using_docker_images.html#determine-your-docker_auth_config-data
    - name: registry.gitlab.com/artesion/private/edge/hivemq-auth-plugin:0.3.0-dev.8
      alias: hivemq-cicd
  script:
    - java --version
    - gradle --version
    - env | sort
    - free -h
    - pwd
    - apt update
    - apt install -y jq httpie
    - time gradle --daemon
    - time gradle $CI_GRADLE_OPTS build | ./jsonl.sh | tee build.log
    - ...
  • What troubleshooting steps have you already taken? Can you link to any docs or other resources so we know where you have been?

We’ve already tried disabling the daemon in every documented way.