@@ -65,20 +65,21 @@ public void analyze() {
65
65
66
66
StringBuilder message = new StringBuilder ();
67
67
for (Map .Entry <String , String > sourceSet : getSourceSets ().get ().entrySet ()) {
68
+ boolean inBuildFile = !sourceSet .getValue ().endsWith ("module-info.java" );
68
69
List <String > toAdd = projectAdvice .stream ().filter (a ->
69
70
a .getToConfiguration () != null && !RUNTIME_ONLY_CONFIGURATION_NAME .equals (getScope (a .getToConfiguration ()).orElse (null ))
70
71
).filter (a ->
71
72
sourceSet .getKey ().equals (sourceSetName (a .getToConfiguration ()))
72
73
).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 )
74
75
).sorted ().collect (Collectors .toList ());
75
76
76
77
List <String > toRemove = projectAdvice .stream ().filter (a ->
77
78
a .getFromConfiguration () != null
78
79
).filter (a ->
79
80
sourceSet .getKey ().equals (sourceSetName (a .getFromConfiguration ()))
80
81
).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 )
82
83
).sorted ().collect (Collectors .toList ());
83
84
84
85
if (!toAdd .isEmpty () || !toRemove .isEmpty ()) {
@@ -92,7 +93,7 @@ public void analyze() {
92
93
message .append ("\n " ).append (String .join ("\n " , toAdd ));
93
94
}
94
95
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) :" );
96
97
message .append ("\n " ).append (String .join ("\n " , toRemove ));
97
98
}
98
99
}
@@ -101,12 +102,20 @@ public void analyze() {
101
102
}
102
103
}
103
104
104
- private String declaration (String conf , String coordinates , Set <String > capabilities ) {
105
+ private String declaration (String conf , String coordinates , Set <String > capabilities , boolean inBuildFile ) {
105
106
String capability = capabilities .isEmpty () ? coordinates : capabilities .iterator ().next ();
106
107
ResolvedArtifactResult moduleJar = getModuleArtifacts ().get ().stream ().flatMap (c -> c .getArtifacts ().stream ()).filter (a ->
107
108
coordinatesEquals (coordinates , capability , a )).findFirst ().orElse (null );
108
109
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
+ }
110
119
} catch (IOException e ) {
111
120
throw new RuntimeException (e );
112
121
}
0 commit comments