Available in versions: Dev (3.22) | Latest (3.21) | 3.20 | 3.19 | 3.18 | 3.17 | 3.16 | 3.15 | 3.14 | 3.13 | 3.12

Caching dependencies

Supported by ✅ Open Source Edition   ✅ Express Edition   ✅ Professional Edition   ✅ Enterprise Edition

Release artifacts never change once they've been published. jOOQ 3.17.35 downloaded today is byte for byte the same as jOOQ 3.17.35 downloaded tomorrow. So there's no need to download it more than once per machine, or once per organisation if you're using a repository manager. Yet, a large part of today's traffic on Maven Central and on https://repo.jooq.org is caused by builds that start with an empty cache every time:

  • Ephemeral CI runners (e.g. GitHub Actions, GitLab CI, Jenkins agents on Kubernetes) without a dependency cache.
  • Docker builds that run mvn or gradle in a layer that is rebuilt whenever any source file changes.
  • Dev containers, cloud IDEs, and sandboxes used by AI coding agents, which often start from a fresh image for every task, and then run the build many times.
  • Dependency update bots, which trigger a full CI build (often across a matrix of JDKs and databases) for every new version of every dependency.

This is slow for you, and expensive for whoever hosts the repository. Maven Central has started responding with HTTP 429 (Too Many Requests) to high-volume consumers, so uncached builds may also start failing. The following sections show how to make sure jOOQ (and all your other dependencies) are downloaded only once.

Keep your local repository

Maven caches artifacts in ~/.m2/repository, Gradle in ~/.gradle/caches. Both tools only download what is missing. To benefit from this:

  • Don't delete these directories as a troubleshooting step. If a single artifact is corrupt, delete only that artifact's directory.
  • Don't routinely use mvn -U (--update-snapshots) or gradle --refresh-dependencies. They're only needed when you want to force a re-check of snapshots or dynamic versions.
  • Don't point -Dmaven.repo.local or GRADLE_USER_HOME to a fresh temporary directory for each build.
  • Once all dependencies are available, you can build without any network access using mvn -o (--offline) or gradle --offline.
  • Prefer the Maven Wrapper (./mvnw) or Gradle Wrapper (./gradlew) if your project has one. The build tool distribution itself is then downloaded once and cached in ~/.m2/wrapper or ~/.gradle/wrapper.

Use a repository manager

In an organisation, the most effective cache is a repository manager like Sonatype Nexus Repository, JFrog Artifactory, or Reposilite, configured as a proxy for Maven Central (and for https://repo.jooq.org, if you're using a commercial edition, using your licensee credentials). Every artifact is then downloaded from the internet only once for the entire organisation, and your builds keep working when a public repository is slow or unavailable.

Maven
Gradle (Kotlin)
Gradle (Groovy)

settings.xml

<mirrors>
    <mirror>
        <id>my-repository-manager</id>

        <!-- Route all requests (Maven Central, repo.jooq.org, ...) through your repository manager -->
        <mirrorOf>*</mirrorOf>
        <url>https://repo.example.com/repository/maven-public/</url>
    </mirror>
</mirrors>

settings.gradle.kts

pluginManagement {
    repositories {
        maven { url = uri("https://repo.example.com/repository/maven-public/") }
    }
}

dependencyResolutionManagement {
    repositories {
        maven { url = uri("https://repo.example.com/repository/maven-public/") }
    }
}

settings.gradle

pluginManagement {
    repositories {
        maven { url "https://repo.example.com/repository/maven-public/" }
    }
}

dependencyResolutionManagement {
    repositories {
        maven { url "https://repo.example.com/repository/maven-public/" }
    }
}

Cache dependencies in CI

Most CI systems can persist the local repository between builds. For example, on GitHub Actions:

- uses: actions/checkout@v5
- uses: actions/setup-java@v5
  with:
    distribution: temurin
    java-version: 21

    # Restores ~/.m2/repository (or ~/.gradle/caches) from previous runs, keyed by your build files
    cache: maven # or: gradle
- run: ./mvnw -B verify

On GitLab CI, move the local repository into the project directory, so it can be cached:

variables:
  MAVEN_OPTS: "-Dmaven.repo.local=$CI_PROJECT_DIR/.m2/repository"

cache:
  key: maven-repository
  paths:
    - .m2/repository/

build:
  script:
    - ./mvnw -B verify

For Gradle on GitLab CI, set GRADLE_USER_HOME: "$CI_PROJECT_DIR/.gradle" and cache .gradle/caches/ and .gradle/wrapper/ in the same way. On Jenkins, prefer persistent agents or a persistent volume for ~/.m2 and ~/.gradle.

If you're using a build matrix (e.g. several JDKs or several databases), make sure all matrix jobs share the same dependency cache rather than each starting with an empty one.

Cache dependencies in Docker builds

When building inside Docker, use a BuildKit cache mount, so the local repository survives between image builds, even if the layer itself is rebuilt:

# syntax=docker/dockerfile:1
FROM maven:3-eclipse-temurin-21 AS build
WORKDIR /src
COPY . .

# For Gradle, use: --mount=type=cache,target=/root/.gradle ./gradlew build
RUN --mount=type=cache,target=/root/.m2 mvn -B package

Avoid docker build --no-cache in automated builds, as it discards this cache as well.

Dev containers, cloud IDEs, and AI coding agents

Environments that are created from scratch for each session or task (dev containers, cloud IDEs, sandboxes of AI coding agents) behave like ephemeral CI runners. To avoid downloading all dependencies again for every session:

  • Mount a persistent volume (or the host's ~/.m2 / ~/.gradle directories) into the container.
  • Or, resolve the dependencies once in the environment's setup step or image (e.g. with mvn dependency:go-offline or ./gradlew dependencies), and run subsequent builds with -o / --offline.
  • Or, configure the environment to use your organisation's repository manager, as shown above.

Declare repositories precisely

If you declare additional repositories (e.g. https://repo.jooq.org for the commercial editions), restrict them to what they actually contain. This avoids unnecessary requests to repositories that can't possibly contain the requested artifact:

  • In Maven, when re-declaring the central repository, add <snapshots><enabled>false</enabled></snapshots>, as Maven Central doesn't host snapshots. For a snapshot-only repository, add <releases><enabled>false</enabled></releases>.
  • In Gradle, use repository content filtering (e.g. content { includeGroupByRegex("org\\.jooq.*") }, mavenContent { snapshotsOnly() }). Avoid an unfiltered mavenLocal().

Feedback

Do you have any feedback about this page? We'd love to hear it!

The jOOQ Logo