From 2a07c83aea2846617db2dfe16d4493d04c1ee0d7 Mon Sep 17 00:00:00 2001 From: Copilot <198982749+Copilot@users.noreply.github.com> Date: Wed, 8 Jul 2026 10:07:54 +0100 Subject: [PATCH] feat: add .mvn/extensions.xml to Maven cache key pattern (#1041) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Initial plan * feat: add .mvn/extensions.xml to Maven cache key pattern Closes #990 Maven build extensions declared in `.mvn/extensions.xml` can introduce additional plugin dependencies (e.g. lifecycle participants, custom packaging types). Including this file in the cache key hash ensures that changes to extensions — which affect what plugin JARs Maven downloads — properly invalidate the cache, preventing stale caches from missing newly-required plugin dependencies. Changes: - src/cache.ts: add `**/.mvn/extensions.xml` to Maven pattern array - __tests__/cache.test.ts: update pattern expectations; add new test - README.md: document the new file in the Maven cache key hash list * test: update maven cache error test name for extensions.xml --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: Bruno Borges --- README.md | 2 +- __tests__/cache.test.ts | 26 ++++++++++++++++++++++---- dist/cleanup/index.js | 6 +++++- dist/setup/index.js | 6 +++++- src/cache.ts | 6 +++++- 5 files changed, 38 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 97194d19..562f9ff5 100644 --- a/README.md +++ b/README.md @@ -138,7 +138,7 @@ Currently, the following distributions are supported: The action has a built-in functionality for caching and restoring dependencies. It uses [toolkit/cache](https://github.com/actions/toolkit/tree/main/packages/cache) under hood for caching dependencies but requires less configuration settings. Supported package managers are gradle, maven and sbt. The format of the used cache key is `setup-java-${{ platform }}-${{ packageManager }}-${{ fileHash }}`, where the hash is based on the following files: - gradle: `**/*.gradle*`, `**/gradle-wrapper.properties`, `buildSrc/**/Versions.kt`, `buildSrc/**/Dependencies.kt`, `gradle/*.versions.toml`, and `**/versions.properties` -- maven: `**/pom.xml` and `**/.mvn/wrapper/maven-wrapper.properties` +- maven: `**/pom.xml`, `**/.mvn/wrapper/maven-wrapper.properties`, and `**/.mvn/extensions.xml` - sbt: all sbt build definition files `**/*.sbt`, `**/project/build.properties`, `**/project/**.scala`, `**/project/**.sbt` When the option `cache-dependency-path` is specified, the hash is based on the matching file. This option supports wildcards and a list of file names, and is especially useful for monorepos. diff --git a/__tests__/cache.test.ts b/__tests__/cache.test.ts index 8a56ef60..69056870 100644 --- a/__tests__/cache.test.ts +++ b/__tests__/cache.test.ts @@ -96,11 +96,11 @@ describe('dependency cache', () => { }); describe('for maven', () => { - it('throws error if no pom.xml or maven-wrapper.properties found', async () => { + it('throws error if no pom.xml, maven-wrapper.properties, or extensions.xml found', async () => { await expect(restore('maven', '')).rejects.toThrow( `No file in ${projectRoot( workspace - )} matched to [**/pom.xml,**/.mvn/wrapper/maven-wrapper.properties], make sure you have checked out the target repository` + )} matched to [**/pom.xml,**/.mvn/wrapper/maven-wrapper.properties,**/.mvn/extensions.xml], make sure you have checked out the target repository` ); }); it('downloads cache based on pom.xml', async () => { @@ -115,7 +115,7 @@ describe('dependency cache', () => { expect.any(String) ); expect(spyGlobHashFiles).toHaveBeenCalledWith( - '**/pom.xml\n**/.mvn/wrapper/maven-wrapper.properties' + '**/pom.xml\n**/.mvn/wrapper/maven-wrapper.properties\n**/.mvn/extensions.xml' ); expect(spyWarning).not.toHaveBeenCalled(); expect(spyInfo).toHaveBeenCalledWith('maven cache is not found'); @@ -136,7 +136,25 @@ describe('dependency cache', () => { expect.any(String) ); expect(spyGlobHashFiles).toHaveBeenCalledWith( - '**/pom.xml\n**/.mvn/wrapper/maven-wrapper.properties' + '**/pom.xml\n**/.mvn/wrapper/maven-wrapper.properties\n**/.mvn/extensions.xml' + ); + expect(spyWarning).not.toHaveBeenCalled(); + expect(spyInfo).toHaveBeenCalledWith('maven cache is not found'); + }); + it('downloads cache based on extensions.xml', async () => { + createDirectory(join(workspace, '.mvn')); + createFile(join(workspace, '.mvn', 'extensions.xml')); + + await restore('maven', ''); + expect(spyCacheRestore).toHaveBeenCalledWith( + [ + join(os.homedir(), '.m2', 'repository'), + join(os.homedir(), '.m2', 'wrapper', 'dists') + ], + expect.any(String) + ); + expect(spyGlobHashFiles).toHaveBeenCalledWith( + '**/pom.xml\n**/.mvn/wrapper/maven-wrapper.properties\n**/.mvn/extensions.xml' ); expect(spyWarning).not.toHaveBeenCalled(); expect(spyInfo).toHaveBeenCalledWith('maven cache is not found'); diff --git a/dist/cleanup/index.js b/dist/cleanup/index.js index 7b073345..4228a683 100644 --- a/dist/cleanup/index.js +++ b/dist/cleanup/index.js @@ -51973,7 +51973,11 @@ const supportedPackageManager = [ (0, path_1.join)(os_1.default.homedir(), '.m2', 'wrapper', 'dists') ], // https://github.com/actions/cache/blob/0638051e9af2c23d10bb70fa9beffcad6cff9ce3/examples.md#java---maven - pattern: ['**/pom.xml', '**/.mvn/wrapper/maven-wrapper.properties'] + pattern: [ + '**/pom.xml', + '**/.mvn/wrapper/maven-wrapper.properties', + '**/.mvn/extensions.xml' + ] }, { id: 'gradle', diff --git a/dist/setup/index.js b/dist/setup/index.js index 50e9c3e0..b1d565c0 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -77838,7 +77838,11 @@ const supportedPackageManager = [ (0, path_1.join)(os_1.default.homedir(), '.m2', 'wrapper', 'dists') ], // https://github.com/actions/cache/blob/0638051e9af2c23d10bb70fa9beffcad6cff9ce3/examples.md#java---maven - pattern: ['**/pom.xml', '**/.mvn/wrapper/maven-wrapper.properties'] + pattern: [ + '**/pom.xml', + '**/.mvn/wrapper/maven-wrapper.properties', + '**/.mvn/extensions.xml' + ] }, { id: 'gradle', diff --git a/src/cache.ts b/src/cache.ts index f91f90c7..42c086c1 100644 --- a/src/cache.ts +++ b/src/cache.ts @@ -28,7 +28,11 @@ const supportedPackageManager: PackageManager[] = [ join(os.homedir(), '.m2', 'wrapper', 'dists') ], // https://github.com/actions/cache/blob/0638051e9af2c23d10bb70fa9beffcad6cff9ce3/examples.md#java---maven - pattern: ['**/pom.xml', '**/.mvn/wrapper/maven-wrapper.properties'] + pattern: [ + '**/pom.xml', + '**/.mvn/wrapper/maven-wrapper.properties', + '**/.mvn/extensions.xml' + ] }, { id: 'gradle',