@@ -65,20 +65,21 @@ public void analyze() {
6565
6666 StringBuilder message = new StringBuilder ();
6767 for (Map .Entry <String , String > sourceSet : getSourceSets ().get ().entrySet ()) {
68+ boolean inBuildFile = !sourceSet .getValue ().endsWith ("module-info.java" );
6869 List <String > toAdd = projectAdvice .stream ().filter (a ->
6970 a .getToConfiguration () != null && !RUNTIME_ONLY_CONFIGURATION_NAME .equals (getScope (a .getToConfiguration ()).orElse (null ))
7071 ).filter (a ->
7172 sourceSet .getKey ().equals (sourceSetName (a .getToConfiguration ()))
7273 ).map (a ->
73- declaration (a .getToConfiguration (), a .getCoordinates ().getIdentifier (), a .getCoordinates ().getGradleVariantIdentification ().getCapabilities ())
74+ declaration (a .getToConfiguration (), a .getCoordinates ().getIdentifier (), a .getCoordinates ().getGradleVariantIdentification ().getCapabilities (), inBuildFile )
7475 ).sorted ().collect (Collectors .toList ());
7576
7677 List <String > toRemove = projectAdvice .stream ().filter (a ->
7778 a .getFromConfiguration () != null
7879 ).filter (a ->
7980 sourceSet .getKey ().equals (sourceSetName (a .getFromConfiguration ()))
8081 ).map (a ->
81- declaration (a .getFromConfiguration (), a .getCoordinates ().getIdentifier (), a .getCoordinates ().getGradleVariantIdentification ().getCapabilities ())
82+ declaration (a .getFromConfiguration (), a .getCoordinates ().getIdentifier (), a .getCoordinates ().getGradleVariantIdentification ().getCapabilities (), inBuildFile )
8283 ).sorted ().collect (Collectors .toList ());
8384
8485 if (!toAdd .isEmpty () || !toRemove .isEmpty ()) {
@@ -92,7 +93,7 @@ public void analyze() {
9293 message .append ("\n " ).append (String .join ("\n " , toAdd ));
9394 }
9495 if (!toRemove .isEmpty ()) {
95- message .append ("\n \n Please remove the following requires directives:" );
96+ message .append ("\n \n Please remove the following requires directives (or change to runtimeOnly) :" );
9697 message .append ("\n " ).append (String .join ("\n " , toRemove ));
9798 }
9899 }
@@ -101,12 +102,20 @@ public void analyze() {
101102 }
102103 }
103104
104- private String declaration (String conf , String coordinates , Set <String > capabilities ) {
105+ private String declaration (String conf , String coordinates , Set <String > capabilities , boolean inBuildFile ) {
105106 String capability = capabilities .isEmpty () ? coordinates : capabilities .iterator ().next ();
106107 ResolvedArtifactResult moduleJar = getModuleArtifacts ().get ().stream ().flatMap (c -> c .getArtifacts ().stream ()).filter (a ->
107108 coordinatesEquals (coordinates , capability , a )).findFirst ().orElse (null );
108109 try {
109- return directive (conf ) + " " + (moduleJar == null ? coordinates : readNameFromModuleFromJarFile (moduleJar .getFile ())) + ";" ;
110+ String moduleName = moduleJar == null ? coordinates : readNameFromModuleFromJarFile (moduleJar .getFile ());
111+ if (inBuildFile ) {
112+ return conf + (coordinates .startsWith (":" )
113+ ? "(project(\" " + coordinates + "\" ))"
114+ : "(gav(\" " + moduleName + "\" ))"
115+ );
116+ } else {
117+ return directive (conf ) + " " + moduleName + ";" ;
118+ }
110119 } catch (IOException e ) {
111120 throw new RuntimeException (e );
112121 }
0 commit comments