Skip to content

build(java): Reduce build time by adding maven build cache - #28476

Open
meluchoMZ wants to merge 1 commit into
prestodb:masterfrom
meluchoMZ:maven-build-cache
Open

meluchoMZ wants to merge 1 commit into
prestodb:masterfrom
meluchoMZ:maven-build-cache

Conversation

@meluchoMZ

@meluchoMZ meluchoMZ commented Sep 11, 2026

Copy link
Copy Markdown

Maven build cache is an extension that allows caching non changing modules, speeding up subsequent builds. This will help reducing local build time during development for developers, especially for the ones with low-end/older machines.

  • Added maven build cache extension
  • Added build cache config

Build time comparision:

  • Hardware: nmve, i71165G7, 16 GB@3200Mhz
  • Software: fedora workstation 44, maven 3.9.11, temurin-17-jdk
  • Build command: mvn install/compile -DskipTests -pl '!presto-docs'

No code changes in neither case

+------------+----------+---------+
| Operation  | no cache |  cache  |
+------------+----------+---------+
|  install   | 5:02 min | 26.438 s|
+------------+----------+---------+
|  compile   | 50:419 s | 17.590 s|
+------------+----------+---------+

When there are changes in a module, only that module is recompiled.

Issues addressed in the cache configuration:

  • dirNames to avoid clean install on cached build to remove target data
  • Added custom execution control to avoid build errors due to interference between takari build system and maven build cache

The maven build cache plugin requires maven 3.9.0, but the projects maven wrapper has been updated to 3.9.12
(#27030)

In case of issues, maven build cache can be disabled with:

-Dmaven.build.cache.enabled=false

This will make compilation the same as before this patch

== NO RELEASE NOTE ==

Description

Motivation and Context

Impact

Test Plan

Contributor checklist

  • Please make sure your submission complies with our contributing guide, in particular code style and commit standards.
  • PR description addresses the issue accurately and concisely. If the change is non-trivial, a GitHub Issue is referenced.
  • Documented new properties (with its default value), SQL syntax, functions, or other functionality.
  • If release notes are required, they follow the release notes guidelines.
  • Adequate tests were added if applicable.
  • CI passed.
  • If adding new dependencies, verified they have an OpenSSF Scorecard score of 5.0 or higher (or obtained explicit TSC approval for lower scores).

Release Notes

Please follow release notes guidelines and fill in the release notes below.

== RELEASE NOTES ==

General Changes
* ... 
* ... 

Hive Connector Changes
* ... 
* ... 

If release note is NOT required, use:

== NO RELEASE NOTE ==

@meluchoMZ
meluchoMZ requested a review from a team as a code owner September 11, 2026 19:58
@sourcery-ai

sourcery-ai Bot commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

Reviewer's Guide

Adds Maven Build Cache Extension 1.3.0 and repository configuration that reuses unchanged module outputs while preserving required generated directories and bypassing cache restoration for Takari lifecycle execution. The Maven wrapper requirement is expected to be Maven 3.9.12 or newer; caching is enabled by default and can be disabled via the documented Maven property.

Flow diagram for cached Maven module builds

flowchart TD
    Start["Maven build"] --> Enabled{"Cache enabled?"}
    Enabled -->|No| Build["Compile modules normally"]
    Enabled -->|Yes| Lookup["Check module build cache"]
    Lookup --> Hit{"Unchanged module?"}
    Hit -->|Yes| Restore["Restore cached outputs"]
    Hit -->|No| Compile["Compile changed module"]
    Compile --> Save["Store module outputs in cache"]
    Restore --> Done["Continue build"]
    Save --> Done
    Build --> Done
Loading

File-Level Changes

Change Details Files
Enable Maven build caching through a project extension and configure which generated build outputs are restored.
  • Add Maven Build Cache Extension 1.3.0 alongside the existing Takari extension.
  • Enable caching with XX hashing and preserve selected target subdirectories and Checkstyle outputs.
  • Configure Takari lifecycle execution to always run, avoiding cache-state restoration conflicts.
.mvn/extensions.xml
.mvn/maven-build-cache-config.xml

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@linux-foundation-easycla

linux-foundation-easycla Bot commented Sep 11, 2026

Copy link
Copy Markdown

CLA Not Signed

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 2 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path=".mvn/maven-build-cache-config.xml" line_range="6" />
<code_context>
+	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+	xsi:schemaLocation="http://maven.apache.org/BUILD-CACHE/1.0.0 http://maven.apache.org/xsd/build-cache-1.0.0.xsd">
+	<configuration>
+		<enabled>true</enabled>
+		<hashAlgorithm>XX</hashAlgorithm>
+		<attachedOutputs>
</code_context>
<issue_to_address>
**issue (bug_risk):** The documented opt-out command `-Dmaven.build.cache.enabled=true` does not disable the cache because the configuration enables it with `true`; users following the instructions still run with build caching enabled.

**Triggers:** When a developer encounters a cache-related build failure and follows the documented disable command.

**Suggested fix:** Change the documented property value to `-Dmaven.build.cache.enabled=false` and verify that the extension property overrides this configuration value.
</issue_to_address>

### Comment 2
<location path=".mvn/extensions.xml" line_range="13-17" />
<code_context>
     </extension>
+	<extension>
+		<groupId>org.apache.maven.extensions</groupId>
+		<artifactId>maven-build-cache-extension</artifactId>
+		<version>1.3.0</version>
+	</extension>
 </extensions>
</code_context>
<issue_to_address>
**issue (bug_risk):** Adding this extension makes the build require Maven 3.9.0 or newer before Maven can load the project, while the repository documentation still advertises Maven 3.6.3+ and users invoking system `mvn` with that version will fail before the build starts.

**Triggers:** When a developer uses the documented Maven 3.6.3–3.8.x system installation instead of the updated wrapper.

**Suggested fix:** Either preserve compatibility with the documented Maven versions, update the minimum Maven requirement/documentation, or ensure the build consistently requires and invokes the Maven wrapper.

```suggestion

```
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread .mvn/maven-build-cache-config.xml
Comment thread .mvn/extensions.xml
Maven build cache is an extension that allows caching non changing
modules, speeding up subsequent builds. This will help reducing local
build time during development for developers, especially for the ones
with low-end/older machines.

 - Added maven build cache extension
 - Added build cache config

Build time comparision:
 - Hardware:  nmve, i71165G7, 16 GB@3200Mhz
 - Software: fedora workstation 44, maven 3.9.11, temurin-17-jdk
 - Build command: `mvn install/compile -DskipTests -pl '!presto-docs'`

No code changes in neither case

```
+------------+----------+---------+
| Operation  | no cache |  cache  |
+------------+----------+---------+
|  install   | 5:02 min | 26.438 s|
+------------+----------+---------+
|  compile   | 50:419 s | 17.590 s|
+------------+----------+---------+
```

When there are changes in a module, only that module is recompiled.

Issues addressed in the cache configuration:
 - `dirNames` to avoid `clean install` on cached build to remove target
   data
 - Added custom execution control to avoid build errors due to
   interference between takari build system and maven build cache

The maven build cache plugin requires maven 3.9.0, but the projects
maven wrapper has been updated to 3.9.12
(prestodb#27030)

In case of issues, maven build cache can be disabled with:

`-Dmaven.build.cache.enabled=false`

This will make compilation the same as before this patch

```
== NO RELEASE NOTE ==
```
@steveburnett

Copy link
Copy Markdown
Contributor
  • Please sign the Presto CLA.

  • Please edit the PR title to follow semantic commit style to pass the failing and required CI check. See the failure in the test for advice. If you can’t edit the PR title let us know and we can help.

  • Please add a release note - or NO RELEASE NOTE - following the Release Notes Guidelines to pass the failing but not required CI check.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants