Skip to content

Do not read a JAR completely into a byte-array before computing the SHA#470

Merged
olamy merged 4 commits intoapache:masterfrom
jvdvegt:ISSUE_469
Apr 17, 2026
Merged

Do not read a JAR completely into a byte-array before computing the SHA#470
olamy merged 4 commits intoapache:masterfrom
jvdvegt:ISSUE_469

Conversation

@jvdvegt
Copy link
Copy Markdown
Contributor

@jvdvegt jvdvegt commented Mar 25, 2026

Following this checklist to help us incorporate your
contribution quickly and easily:

  • Your pull request should address just one issue, without pulling in other changes.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Each commit in the pull request should have a meaningful subject line and body.
    Note that commits might be squashed by a maintainer on merge.
  • Write unit tests that match behavioral changes, where the tests fail if the changes to the runtime are not applied.
    This may not always be possible but is a best-practice.
  • Run mvn verify to make sure basic checks pass.
    NB: this fails on 'null/org/apache/maven/extensions/maven-build-cache-extension/${projectVersion}/maven-build-cache-extension-${projectVersion}.pom.lastUpdated', which seems unrelated).
    A more thorough check will be performed on your pull request automatically.
  • You have run the integration tests successfully (mvn -Prun-its verify).

If your pull request is about ~20 lines of code you don't need to sign an
Individual Contributor License Agreement if you are unsure
please ask on the developers list.

To make clear that you license your contribution under
the Apache License Version 2.0, January 2004
you have to acknowledge this by using the following check-box.

@olamy
Copy link
Copy Markdown
Member

olamy commented Mar 30, 2026

Looks like a very good improvement! Thanks!
I wonder if you could mention this in this documentation page https://maven.apache.org/extensions/maven-build-cache-extension/performance.html

@olamy olamy linked an issue Mar 30, 2026 that may be closed by this pull request
@olamy olamy changed the title ISSUE_469: Add '_MM' versions for all SHA-algorithms, which prevents… Do not read a JAR completely into a byte-array before computing the SHA Mar 30, 2026
@jvdvegt
Copy link
Copy Markdown
Contributor Author

jvdvegt commented Apr 3, 2026

Looks like a very good improvement! Thanks! I wonder if you could mention this in this documentation page https://maven.apache.org/extensions/maven-build-cache-extension/performance.html

Yes, will do!

Update @olamy : is this really the source for the docs? An SVN-repo? https://svn.apache.org/repos/asf/maven/website/components/extensions/maven-build-cache-extension/performance.html

That has been a while! How do I get access? I'd like to add a paragraph right after the 'General notes' part:

Supported hash algorithms

The following hash algorithms are supported:

  • METRO
  • SHA1
  • SHA256
  • SHA384
  • SHA512
  • XX

All algorithms come in two flavors: the default one, which fully reads artifacts in memory, and a 'memory mapped' version, which reduces memory requirements but needs additional --add-opens on JDK >= 17 (see below). The memory mapped version of an algorithm has a _MM postfix added to the algorithm name, e..g SHA1_MM (note that as an exception, XXMM has no underscore in its name).

To use the Memory Mapped versions to algorithms, the file .mvn/jvm.config needs to be present in the top directory of your project with the following line to run successfully on JDK >= 17.

--add-opens java.base/sun.nio.ch=ALL-UNNAMED

Hash algorithm selection

By default, the cache uses the XX algorithm, which is a very fast hash algorithm and should be enough for most use cases. In projects with a large codebase, the performance of hash algorithms becomes more critical, and other algorithms like XXMM (XX with memory-mapped files) could provide better performance, depending on the environment.

<hashAlgorithm>XX</hashAlgorithm>

Filter out unnecessary artifacts

@olamy
Copy link
Copy Markdown
Member

olamy commented Apr 13, 2026

@olamy olamy added the enhancement New feature or request label Apr 16, 2026
@olamy
Copy link
Copy Markdown
Member

olamy commented Apr 16, 2026

@jvdvegt thanks for your hard. I fixed test in master. can you just rebase, we get a last green build and this will be merged

@jvdvegt
Copy link
Copy Markdown
Contributor Author

jvdvegt commented Apr 17, 2026

@olamy : I think I rebased it (I'm not very familiar with GitHub multi-repos). Thanks for reviewing this!

@olamy olamy merged commit d5722ad into apache:master Apr 17, 2026
22 checks passed
@github-actions github-actions bot added this to the 1.2.3 milestone Apr 17, 2026
@olamy
Copy link
Copy Markdown
Member

olamy commented Apr 17, 2026

@jvdvegt all merged. Thanks for your contribution! (and patience :) )

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

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Do not read a JAR completely into a byte-array before computing the SHA.

3 participants