2323import org .gradle .api .artifacts .component .ModuleComponentIdentifier ;
2424import org .gradle .api .artifacts .component .ProjectComponentIdentifier ;
2525import org .gradle .api .artifacts .result .ResolvedArtifactResult ;
26+ import org .gradle .api .capabilities .Capability ;
2627import org .gradle .api .provider .ListProperty ;
2728import org .gradle .api .provider .MapProperty ;
2829import org .gradle .api .tasks .Input ;
@@ -69,15 +70,15 @@ public void analyze() {
6970 ).filter (a ->
7071 sourceSet .getKey ().equals (sourceSetName (a .getToConfiguration ()))
7172 ).map (a ->
72- declaration (a .getToConfiguration (), a .getCoordinates ().getIdentifier ())
73+ declaration (a .getToConfiguration (), a .getCoordinates ().getIdentifier (), a . getCoordinates (). getGradleVariantIdentification (). getCapabilities () )
7374 ).sorted ().collect (Collectors .toList ());
7475
7576 List <String > toRemove = projectAdvice .stream ().filter (a ->
7677 a .getFromConfiguration () != null
7778 ).filter (a ->
7879 sourceSet .getKey ().equals (sourceSetName (a .getFromConfiguration ()))
7980 ).map (a ->
80- declaration (a .getFromConfiguration (), a .getCoordinates ().getIdentifier ())
81+ declaration (a .getFromConfiguration (), a .getCoordinates ().getIdentifier (), a . getCoordinates (). getGradleVariantIdentification (). getCapabilities () )
8182 ).sorted ().collect (Collectors .toList ());
8283
8384 if (!toAdd .isEmpty () || !toRemove .isEmpty ()) {
@@ -88,29 +89,35 @@ public void analyze() {
8889 }
8990 if (!toAdd .isEmpty ()) {
9091 message .append ("\n \n Please add the following requires directives:" );
91- message .append ("\n " ).append (String .join ("; \n " , toAdd )). append ( ";" );
92+ message .append ("\n " ).append (String .join ("\n " , toAdd ));
9293 }
9394 if (!toRemove .isEmpty ()) {
9495 message .append ("\n \n Please remove the following requires directives:" );
95- message .append ("\n " ).append (String .join ("; \n " , toRemove )). append ( ";" );
96+ message .append ("\n " ).append (String .join ("\n " , toRemove ));
9697 }
9798 }
9899 if (message .length () > 0 ) {
99100 throw new RuntimeException (message .toString ());
100101 }
101102 }
102103
103- private String declaration (String conf , String coordinates ) {
104+ private String declaration (String conf , String coordinates , Set <String > capabilities ) {
105+ String capability = capabilities .isEmpty () ? coordinates : capabilities .iterator ().next ();
104106 ResolvedArtifactResult moduleJar = getModuleArtifacts ().get ().stream ().flatMap (c -> c .getArtifacts ().stream ()).filter (a ->
105- coordinatesEquals (coordinates , a . getId (). getComponentIdentifier () )).findFirst ().orElse (null );
107+ coordinatesEquals (coordinates , capability , a )).findFirst ().orElse (null );
106108 try {
107- return directive (conf ) + " " + (moduleJar == null ? coordinates : readNameFromModuleFromJarFile (moduleJar .getFile ()));
109+ return directive (conf ) + " " + (moduleJar == null ? coordinates : readNameFromModuleFromJarFile (moduleJar .getFile ())) + ";" ;
108110 } catch (IOException e ) {
109111 throw new RuntimeException (e );
110112 }
111113 }
112114
113- private boolean coordinatesEquals (String coordinates , ComponentIdentifier id ) {
115+ private boolean coordinatesEquals (String coordinates , String capability , ResolvedArtifactResult selected ) {
116+ ComponentIdentifier id = selected .getId ().getComponentIdentifier ();
117+ List <Capability > capabilities = selected .getVariant ().getCapabilities ();
118+ if (capabilities .stream ().noneMatch (c -> capability .endsWith (":" + c .getName ()))) {
119+ return false ;
120+ }
114121 if (id instanceof ModuleComponentIdentifier ) {
115122 return coordinates .equals (((ModuleComponentIdentifier ) id ).getModuleIdentifier ().toString ());
116123 }
0 commit comments