@@ -416,13 +416,62 @@ private ConditionalDependency getOrCreateConditionalDep(Dependency dep) {
416
416
key -> newConditionalDep (dep ));
417
417
}
418
418
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
+
419
450
private ConditionalDependency newConditionalDep (Dependency dep ) {
420
451
final Configuration config = project .getConfigurations ().detachedConfiguration (dep ).setTransitive (false );
421
452
setConditionalAttributes (config , project , mode );
453
+ ResolvedArtifact resolvedArtifact = null ;
454
+
422
455
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 );
424
464
}
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
+
426
475
}
427
476
428
477
private class ProcessedDependency {
0 commit comments