Skip to content

Commit 78efe03

Browse files
Copilotbrunoborges
andcommitted
feat: add .mvn/extensions.xml to Maven cache key pattern (actions#1041)
* Initial plan * feat: add .mvn/extensions.xml to Maven cache key pattern Closes actions#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 <brborges@microsoft.com> (cherry picked from commit 2a07c83)
1 parent 3be16b5 commit 78efe03

5 files changed

Lines changed: 38 additions & 8 deletions

File tree

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ Currently, the following distributions are supported:
138138
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:
139139

140140
- gradle: `**/*.gradle*`, `**/gradle-wrapper.properties`, `buildSrc/**/Versions.kt`, `buildSrc/**/Dependencies.kt`, `gradle/*.versions.toml`, and `**/versions.properties`
141-
- maven: `**/pom.xml` and `**/.mvn/wrapper/maven-wrapper.properties`
141+
- maven: `**/pom.xml`, `**/.mvn/wrapper/maven-wrapper.properties`, and `**/.mvn/extensions.xml`
142142
- sbt: all sbt build definition files `**/*.sbt`, `**/project/build.properties`, `**/project/**.scala`, `**/project/**.sbt`
143143

144144
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.

‎__tests__/cache.test.ts‎

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,11 @@ describe('dependency cache', () => {
9696
});
9797

9898
describe('for maven', () => {
99-
it('throws error if no pom.xml or maven-wrapper.properties found', async () => {
99+
it('throws error if no pom.xml, maven-wrapper.properties, or extensions.xml found', async () => {
100100
await expect(restore('maven', '')).rejects.toThrow(
101101
`No file in ${projectRoot(
102102
workspace
103-
)} matched to [**/pom.xml,**/.mvn/wrapper/maven-wrapper.properties], make sure you have checked out the target repository`
103+
)} matched to [**/pom.xml,**/.mvn/wrapper/maven-wrapper.properties,**/.mvn/extensions.xml], make sure you have checked out the target repository`
104104
);
105105
});
106106
it('downloads cache based on pom.xml', async () => {
@@ -115,7 +115,7 @@ describe('dependency cache', () => {
115115
expect.any(String)
116116
);
117117
expect(spyGlobHashFiles).toHaveBeenCalledWith(
118-
'**/pom.xml\n**/.mvn/wrapper/maven-wrapper.properties'
118+
'**/pom.xml\n**/.mvn/wrapper/maven-wrapper.properties\n**/.mvn/extensions.xml'
119119
);
120120
expect(spyWarning).not.toHaveBeenCalled();
121121
expect(spyInfo).toHaveBeenCalledWith('maven cache is not found');
@@ -136,7 +136,25 @@ describe('dependency cache', () => {
136136
expect.any(String)
137137
);
138138
expect(spyGlobHashFiles).toHaveBeenCalledWith(
139-
'**/pom.xml\n**/.mvn/wrapper/maven-wrapper.properties'
139+
'**/pom.xml\n**/.mvn/wrapper/maven-wrapper.properties\n**/.mvn/extensions.xml'
140+
);
141+
expect(spyWarning).not.toHaveBeenCalled();
142+
expect(spyInfo).toHaveBeenCalledWith('maven cache is not found');
143+
});
144+
it('downloads cache based on extensions.xml', async () => {
145+
createDirectory(join(workspace, '.mvn'));
146+
createFile(join(workspace, '.mvn', 'extensions.xml'));
147+
148+
await restore('maven', '');
149+
expect(spyCacheRestore).toHaveBeenCalledWith(
150+
[
151+
join(os.homedir(), '.m2', 'repository'),
152+
join(os.homedir(), '.m2', 'wrapper', 'dists')
153+
],
154+
expect.any(String)
155+
);
156+
expect(spyGlobHashFiles).toHaveBeenCalledWith(
157+
'**/pom.xml\n**/.mvn/wrapper/maven-wrapper.properties\n**/.mvn/extensions.xml'
140158
);
141159
expect(spyWarning).not.toHaveBeenCalled();
142160
expect(spyInfo).toHaveBeenCalledWith('maven cache is not found');

‎dist/cleanup/index.js‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51973,7 +51973,11 @@ const supportedPackageManager = [
5197351973
(0, path_1.join)(os_1.default.homedir(), '.m2', 'wrapper', 'dists')
5197451974
],
5197551975
// https://github.com/actions/cache/blob/0638051e9af2c23d10bb70fa9beffcad6cff9ce3/examples.md#java---maven
51976-
pattern: ['**/pom.xml', '**/.mvn/wrapper/maven-wrapper.properties']
51976+
pattern: [
51977+
'**/pom.xml',
51978+
'**/.mvn/wrapper/maven-wrapper.properties',
51979+
'**/.mvn/extensions.xml'
51980+
]
5197751981
},
5197851982
{
5197951983
id: 'gradle',

‎dist/setup/index.js‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77838,7 +77838,11 @@ const supportedPackageManager = [
7783877838
(0, path_1.join)(os_1.default.homedir(), '.m2', 'wrapper', 'dists')
7783977839
],
7784077840
// https://github.com/actions/cache/blob/0638051e9af2c23d10bb70fa9beffcad6cff9ce3/examples.md#java---maven
77841-
pattern: ['**/pom.xml', '**/.mvn/wrapper/maven-wrapper.properties']
77841+
pattern: [
77842+
'**/pom.xml',
77843+
'**/.mvn/wrapper/maven-wrapper.properties',
77844+
'**/.mvn/extensions.xml'
77845+
]
7784277846
},
7784377847
{
7784477848
id: 'gradle',

‎src/cache.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,11 @@ const supportedPackageManager: PackageManager[] = [
2828
join(os.homedir(), '.m2', 'wrapper', 'dists')
2929
],
3030
// https://github.com/actions/cache/blob/0638051e9af2c23d10bb70fa9beffcad6cff9ce3/examples.md#java---maven
31-
pattern: ['**/pom.xml', '**/.mvn/wrapper/maven-wrapper.properties']
31+
pattern: [
32+
'**/pom.xml',
33+
'**/.mvn/wrapper/maven-wrapper.properties',
34+
'**/.mvn/extensions.xml'
35+
]
3236
},
3337
{
3438
id: 'gradle',

0 commit comments

Comments
 (0)