Skip to content

Commit 69ebd3f

Browse files
committed
Try to handle relocation artifacts gracefully in QuarkusComponentVariants
1 parent c0ce55e commit 69ebd3f

File tree

1 file changed

+51
-2
lines changed

1 file changed

+51
-2
lines changed

devtools/gradle/gradle-model/src/main/java/io/quarkus/gradle/dependency/QuarkusComponentVariants.java

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -416,13 +416,62 @@ private ConditionalDependency getOrCreateConditionalDep(Dependency dep) {
416416
key -> newConditionalDep(dep));
417417
}
418418

419+
private ResolvedArtifact tryResolvingRelocationArtifact(Dependency dep) {
420+
final Configuration configForRelocated = project.getConfigurations().detachedConfiguration(dep).setTransitive(true);
421+
setConditionalAttributes(configForRelocated, project, mode);
422+
423+
var firstLevelDeps = configForRelocated.getResolvedConfiguration().getFirstLevelModuleDependencies();
424+
if (firstLevelDeps.size() != 1) {
425+
return null;
426+
}
427+
ResolvedDependency resolvedDep = firstLevelDeps.iterator().next();
428+
429+
// If resolved dep is indeed relocated, it should have exactly one child and we assume
430+
// that child is the actual artifact we want.
431+
var childrenDeps = resolvedDep.getChildren();
432+
if (childrenDeps.size() != 1) {
433+
return null;
434+
}
435+
ResolvedDependency relocatedDep = childrenDeps.iterator().next();
436+
437+
var resolvedArtifacts = relocatedDep.getModuleArtifacts();
438+
if (resolvedArtifacts.size() != 1) {
439+
return null;
440+
}
441+
442+
ResolvedArtifact artifact = resolvedArtifacts.iterator().next();
443+
if (ArtifactCoords.TYPE_POM.equals(artifact.getExtension())) {
444+
return null;
445+
}
446+
447+
return artifact;
448+
}
449+
419450
private ConditionalDependency newConditionalDep(Dependency dep) {
420451
final Configuration config = project.getConfigurations().detachedConfiguration(dep).setTransitive(false);
421452
setConditionalAttributes(config, project, mode);
453+
ResolvedArtifact resolvedArtifact = null;
454+
422455
for (var a : config.getResolvedConfiguration().getResolvedArtifacts()) {
423-
return new ConditionalDependency(getKey(a), a, DependencyUtils.getExtensionInfoOrNull(project, a));
456+
resolvedArtifact = a;
457+
break;
458+
}
459+
460+
if (resolvedArtifact == null) {
461+
// likely a relocation artifact, in which case we want to resolve it with transitive deps and
462+
// take the first artifact.
463+
resolvedArtifact = tryResolvingRelocationArtifact(dep);
424464
}
425-
throw new RuntimeException(dep + " did not resolve to any artifacts");
465+
466+
if (resolvedArtifact == null) {
467+
throw new RuntimeException(dep + " did not resolve to any artifacts");
468+
}
469+
470+
return new ConditionalDependency(
471+
getKey(resolvedArtifact),
472+
resolvedArtifact,
473+
DependencyUtils.getExtensionInfoOrNull(project, resolvedArtifact));
474+
426475
}
427476

428477
private class ProcessedDependency {

0 commit comments

Comments
 (0)