From 6dc10d31ce6c9f906fd7bae8cccdaf045a82ea7e Mon Sep 17 00:00:00 2001 From: mahabaleshwars <147705296+mahabaleshwars@users.noreply.github.com> Date: Fri, 19 Jun 2026 14:10:45 +0530 Subject: [PATCH 1/2] add Maven Wrapper distribution caching --- README.md | 2 +- __tests__/cache.test.ts | 23 ++++++++++++++++++++--- dist/cleanup/index.js | 7 +++++-- dist/setup/index.js | 7 +++++-- src/cache.ts | 7 +++++-- 5 files changed, 36 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 8a7392a9f..ec24882f0 100644 --- a/README.md +++ b/README.md @@ -137,7 +137,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` +- maven: `**/pom.xml` and `**/.mvn/wrapper/maven-wrapper.properties` - 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 df7a59bd4..2f1055e5f 100644 --- a/__tests__/cache.test.ts +++ b/__tests__/cache.test.ts @@ -100,15 +100,32 @@ describe('dependency cache', () => { await expect(restore('maven', '')).rejects.toThrow( `No file in ${projectRoot( workspace - )} matched to [**/pom.xml], make sure you have checked out the target repository` + )} matched to [**/pom.xml,**/.mvn/wrapper/maven-wrapper.properties], make sure you have checked out the target repository` ); }); - it('downloads cache', async () => { + it('downloads cache based on pom.xml', async () => { createFile(join(workspace, 'pom.xml')); await restore('maven', ''); expect(spyCacheRestore).toHaveBeenCalled(); - expect(spyGlobHashFiles).toHaveBeenCalledWith('**/pom.xml'); + expect(spyGlobHashFiles).toHaveBeenCalledWith( + '**/pom.xml\n**/.mvn/wrapper/maven-wrapper.properties' + ); + expect(spyWarning).not.toHaveBeenCalled(); + expect(spyInfo).toHaveBeenCalledWith('maven cache is not found'); + }); + it('downloads cache based on maven-wrapper.properties', async () => { + createDirectory(join(workspace, '.mvn')); + createDirectory(join(workspace, '.mvn', 'wrapper')); + createFile( + join(workspace, '.mvn', 'wrapper', 'maven-wrapper.properties') + ); + + await restore('maven', ''); + expect(spyCacheRestore).toHaveBeenCalled(); + expect(spyGlobHashFiles).toHaveBeenCalledWith( + '**/pom.xml\n**/.mvn/wrapper/maven-wrapper.properties' + ); 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 5b4454754..cef7d45bc 100644 --- a/dist/cleanup/index.js +++ b/dist/cleanup/index.js @@ -51734,9 +51734,12 @@ const CACHE_KEY_PREFIX = 'setup-java'; const supportedPackageManager = [ { id: 'maven', - path: [(0, path_1.join)(os_1.default.homedir(), '.m2', 'repository')], + path: [ + (0, path_1.join)(os_1.default.homedir(), '.m2', 'repository'), + (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'] + pattern: ['**/pom.xml', '**/.mvn/wrapper/maven-wrapper.properties'] }, { id: 'gradle', diff --git a/dist/setup/index.js b/dist/setup/index.js index 8e2595766..6551d3954 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -77598,9 +77598,12 @@ const CACHE_KEY_PREFIX = 'setup-java'; const supportedPackageManager = [ { id: 'maven', - path: [(0, path_1.join)(os_1.default.homedir(), '.m2', 'repository')], + path: [ + (0, path_1.join)(os_1.default.homedir(), '.m2', 'repository'), + (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'] + pattern: ['**/pom.xml', '**/.mvn/wrapper/maven-wrapper.properties'] }, { id: 'gradle', diff --git a/src/cache.ts b/src/cache.ts index 7d13839ee..ccd4e211f 100644 --- a/src/cache.ts +++ b/src/cache.ts @@ -23,9 +23,12 @@ interface PackageManager { const supportedPackageManager: PackageManager[] = [ { id: 'maven', - path: [join(os.homedir(), '.m2', 'repository')], + path: [ + join(os.homedir(), '.m2', 'repository'), + join(os.homedir(), '.m2', 'wrapper', 'dists') + ], // https://github.com/actions/cache/blob/0638051e9af2c23d10bb70fa9beffcad6cff9ce3/examples.md#java---maven - pattern: ['**/pom.xml'] + pattern: ['**/pom.xml', '**/.mvn/wrapper/maven-wrapper.properties'] }, { id: 'gradle', From 614a228ff32ce53459e38d4f074b5ba630877c4a Mon Sep 17 00:00:00 2001 From: mahabaleshwars <147705296+mahabaleshwars@users.noreply.github.com> Date: Fri, 19 Jun 2026 14:59:32 +0530 Subject: [PATCH 2/2] update test case --- __tests__/cache.test.ts | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/__tests__/cache.test.ts b/__tests__/cache.test.ts index 2f1055e5f..48502f112 100644 --- a/__tests__/cache.test.ts +++ b/__tests__/cache.test.ts @@ -96,7 +96,7 @@ describe('dependency cache', () => { }); describe('for maven', () => { - it('throws error if no pom.xml found', async () => { + it('throws error if no pom.xml or maven-wrapper.properties found', async () => { await expect(restore('maven', '')).rejects.toThrow( `No file in ${projectRoot( workspace @@ -107,7 +107,13 @@ describe('dependency cache', () => { createFile(join(workspace, 'pom.xml')); await restore('maven', ''); - expect(spyCacheRestore).toHaveBeenCalled(); + 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' ); @@ -122,7 +128,13 @@ describe('dependency cache', () => { ); await restore('maven', ''); - expect(spyCacheRestore).toHaveBeenCalled(); + 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' );