Skip to content

[Java] Speed up Java quickstart validation by caching Maven dependencies in CI #1312

@javier-aliaga

Description

@javier-aliaga

Problem

The Validate java quickstart workflow (.github/workflows/validate_java_quickstarts.yaml)
currently re-downloads all Maven dependencies on every run.

Looking at the repo, there are ~30 pom.xml files spread across state_management/,
jobs/, service_invocation/, configuration/, workflows/ and tutorials/workflow/.
The validation step iterates over each building block and runs make validate (which
ultimately invokes Maven), so the same artifacts (Dapr SDK, Spring Boot, JUnit,
Testcontainers, etc.) are fetched from Maven Central many times per job — and again
on every PR / push.

The current setup-java step does not enable any cache:

- name: Set up OpenJDK 17
  uses: actions/setup-java@v3
  with:
    distribution: 'adopt'
    java-version: 17

Proposal

Enable Maven dependency caching in the Java validation workflow. Two complementary
changes:

1. Enable built-in Maven cache on setup-java

Upgrade the action and turn on the built-in cache, which hashes all **/pom.xml
files automatically:

- name: Set up OpenJDK 17
  uses: actions/setup-java@v4
  with:
    distribution: 'temurin'
    java-version: 17
    cache: 'maven'

This already covers the majority of the speedup with a one-line change.

2. (Optional) Add restore-keys fallback via actions/cache@v4

If we want partial cache restoration when a single pom.xml changes (common in PRs
that touch one quickstart), we can use actions/cache directly with a restore-keys
fallback:

- name: Cache Maven dependencies
  uses: actions/cache@v4
  with:
    path: ~/.m2/repository
    key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
    restore-keys: |
      ${{ runner.os }}-maven-

Side cleanup (same PR)

While touching this file, also:

  • Bump actions/checkout@v2@v4
  • Replace deprecated distribution: 'adopt' with 'temurin'

Expected impact

  • Significantly faster Java validation runs on warm cache (most artifacts served
    from ~/.m2/repository instead of Maven Central).
  • Less load on Maven Central from CI.
  • No behavior change in what gets validated.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions