Skip to content

Commit

Permalink
fix(gradle): correct handling of heuristically matched dependency tri…
Browse files Browse the repository at this point in the history
…ples
  • Loading branch information
Churro committed Jan 8, 2025
1 parent adede1d commit 55e2455
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
11 changes: 11 additions & 0 deletions lib/modules/manager/gradle/parser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -770,6 +770,17 @@ describe('modules/manager/gradle/parser', () => {
const { deps } = parseGradle(input);
expect(deps).toMatchObject([output].filter(is.truthy));
});

it('handles 3 independent dependencies mismatched as groupId, artifactId, version', () => {
const { deps } = parseGradle(
'someConfig("foo:bar:1.2.3", "foo:baz:4.5.6", "foo:qux:7.8.9")',
);
expect(deps).toMatchObject([
{ depName: 'foo:bar', currentValue: '1.2.3' },
{ depName: 'foo:baz', currentValue: '4.5.6' },
{ depName: 'foo:qux', currentValue: '7.8.9' },
]);
});
});

describe('calculations', () => {
Expand Down
18 changes: 17 additions & 1 deletion lib/modules/manager/gradle/parser/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { regEx } from '../../../../util/regex';
import type { PackageDependency } from '../../types';
import type { parseGradle as parseGradleCallback } from '../parser';
import type { Ctx, GradleManagerData } from '../types';
import { parseDependencyString } from '../utils';
import { isDependencyString, parseDependencyString } from '../utils';
import {
GRADLE_PLUGINS,
REGISTRY_URLS,
Expand Down Expand Up @@ -169,6 +169,22 @@ export function handleLongFormDep(ctx: Ctx): Ctx {
return ctx;
}

// Special handling: 3 independent dependencies mismatched as groupId, artifactId, version
if (
isDependencyString(groupId) &&
isDependencyString(artifactId) &&
isDependencyString(version)
) {
ctx.tokenMap.templateStringTokens = groupIdTokens;
handleDepString(ctx);
ctx.tokenMap.templateStringTokens = artifactIdTokens;
handleDepString(ctx);
ctx.tokenMap.templateStringTokens = versionTokens;
handleDepString(ctx);

return ctx;
}

const dep = parseDependencyString([groupId, artifactId, version].join(':'));
if (!dep) {
return ctx;
Expand Down

0 comments on commit 55e2455

Please sign in to comment.