Skip to content

Commit

Permalink
feat(manager/maven): Support variables for package replacements
Browse files Browse the repository at this point in the history
This should fix renovatebot#34088
  • Loading branch information
jonasrutishauser committed Feb 20, 2025
1 parent 5ec3340 commit f7156ef
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 1 deletion.
36 changes: 36 additions & 0 deletions lib/modules/manager/maven/extract.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,10 @@ describe('modules/manager/maven/extract', () => {
depName: 'com.sksamuel.scapegoat:scalac-scapegoat-plugin_2.13.7',
currentValue: '1.4.11',
},
{
depName: 'com.sksamuel.scapegoat:scalac-scapegoat-plugin_2.13.7',
currentValue: '1.4.11',
},
]);
});

Expand All @@ -298,6 +302,10 @@ describe('modules/manager/maven/extract', () => {
depName: 'org.apache.lucene:lucene-core-1.2.3.1.2.3',
currentValue: '1.2.3',
},
{
depName: 'org.apache.lucene:lucene-core-1.2.3.1.2.3',
currentValue: '1.2.3',
},
]);
});

Expand Down Expand Up @@ -575,6 +583,20 @@ describe('modules/manager/maven/extract', () => {
],
skipReason: 'name-placeholder',
},
{
currentValue: '1.2.3.4',
datasource: 'maven',
depName: 'org.example:quux',
depType: 'compile',
editFile: 'parent.pom.xml',
fileReplacePosition: 2426,
sharedVariableName: 'quuxVersion',
registryUrls: [
'http://example.com/',
'http://example.com/nexus/xyz',
'https://repo.maven.apache.org/maven2',
],
},
{
currentValue: '1.2.3',
datasource: 'maven',
Expand Down Expand Up @@ -698,11 +720,25 @@ describe('modules/manager/maven/extract', () => {
depName: 'org.example:quux',
currentValue: '1.2.3.4',
sharedVariableName: 'quuxVersion',
fileReplacePosition: 698,
},
{
depName: 'org.example:quux',
currentValue: '1.2.3.4',
sharedVariableName: 'quuxVersion',
fileReplacePosition: 2779,
},
{
depName: 'org.example:quux-test',
currentValue: '1.2.3.4',
sharedVariableName: 'quuxVersion',
fileReplacePosition: 698,
},
{
depName: 'org.example:quux-test',
currentValue: '1.2.3.4',
sharedVariableName: 'quuxVersion',
fileReplacePosition: 2938,
},
{
depName: 'org.example:quuz',
Expand Down
7 changes: 7 additions & 0 deletions lib/modules/manager/maven/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,13 @@ export function resolveParents(packages: PackageFile[]): PackageFile[] {
}
const sourceName = dep.propSource ?? name;
extractedDeps[sourceName].push(dep);
if (dep.sharedVariableName) {
extractedDeps[name].push({
...dep,
registryUrls: [...dep.registryUrls!],
fileReplacePosition: rawDep.fileReplacePosition,
});
}
});
});

Expand Down
6 changes: 5 additions & 1 deletion lib/modules/manager/maven/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,11 @@ export function updateAtPosition(
}
if (version === currentValue || upgrade.sharedVariableName) {
// TODO: validate newValue (#22198)
const replacedPart = versionPart.replace(version, newValue!);
const versionElement = leftPart.slice(leftPart.lastIndexOf('<'));
const replacedPart = versionPart.replace(
versionElement === '<version>' ? currentValue! : version,
newValue!,
);
return leftPart + replacedPart + restPart;
}
logger.debug({ depName, version, currentValue, newValue }, 'Unknown value');
Expand Down

0 comments on commit f7156ef

Please sign in to comment.