@@ -153,7 +153,12 @@ public J visitMethodInvocation(J.MethodInvocation method, ExecutionContext ctx)
153153 if (!(pluginArgs .get (0 ) instanceof J .Literal )) {
154154 return m ;
155155 }
156- String pluginId = literalValue (pluginArgs .get (0 ));
156+ String pluginId ;
157+ if ("kotlin" .equals (((J .MethodInvocation ) m .getSelect ()).getSimpleName ())) {
158+ pluginId = "kotlin" ;
159+ } else {
160+ pluginId = literalValue (pluginArgs .get (0 ));
161+ }
157162 if (pluginId == null || !StringUtils .matchesGlob (pluginId , pluginIdPattern )) {
158163 return m ;
159164 }
@@ -162,8 +167,15 @@ public J visitMethodInvocation(J.MethodInvocation method, ExecutionContext ctx)
162167 try {
163168 String currentVersion = literalValue (versionArgs .get (0 ));
164169 if (currentVersion != null ) {
165- String resolvedVersion = new DependencyVersionSelector (metadataFailures , gradleProject , gradleSettings )
166- .select (new GroupArtifactVersion (pluginId , pluginId + ".gradle.plugin" , currentVersion ), "classpath" , newVersion , versionPattern , ctx );
170+ String resolvedVersion ;
171+ if ("kotlin" .equals (pluginId )) {
172+ String fullPluginId = String .format ("org.jetbrains.%s.%s" , pluginId , literalValue (pluginArgs .get (0 )));
173+ resolvedVersion = new DependencyVersionSelector (metadataFailures , gradleProject , gradleSettings )
174+ .select (new GroupArtifactVersion (fullPluginId , fullPluginId + ".gradle.plugin" , currentVersion ), "classpath" , newVersion , versionPattern , ctx );
175+ } else {
176+ resolvedVersion = new DependencyVersionSelector (metadataFailures , gradleProject , gradleSettings )
177+ .select (new GroupArtifactVersion (pluginId , pluginId + ".gradle.plugin" , currentVersion ), "classpath" , newVersion , versionPattern , ctx );
178+ }
167179 acc .pluginIdToNewVersion .put (pluginId , resolvedVersion );
168180 } else if (versionArgs .get (0 ) instanceof G .GString ) {
169181 G .GString gString = (G .GString ) versionArgs .get (0 );
@@ -236,7 +248,12 @@ public J visitMethodInvocation(J.MethodInvocation method, ExecutionContext ctx)
236248 }
237249 assert m .getSelect () != null ;
238250 List <Expression > pluginArgs = ((J .MethodInvocation ) m .getSelect ()).getArguments ();
239- String pluginId = literalValue (pluginArgs .get (0 ));
251+ String pluginId ;
252+ if ("kotlin" .equals (((J .MethodInvocation ) m .getSelect ()).getSimpleName ())) {
253+ pluginId = "kotlin" ;
254+ } else {
255+ pluginId = literalValue (pluginArgs .get (0 ));
256+ }
240257 if (pluginId == null || !StringUtils .matchesGlob (pluginId , pluginIdPattern )) {
241258 return m ;
242259 }
@@ -264,8 +281,15 @@ public J visitVariable(J.VariableDeclarations.NamedVariable variable, ExecutionC
264281 String oldVersion = literalValue (initializer );
265282 String newVersion = acc .pluginIdToNewVersion .get (acc .versionPropNameToPluginId .get (visited .getSimpleName ()));
266283 if (newVersion != null && !newVersion .equals (oldVersion )) {
267- String valueSource = initializer .getValueSource () == null || oldVersion == null ? initializer .getValueSource () : initializer .getValueSource ().replace (oldVersion , newVersion );
268- return visited .withInitializer (initializer .withValueSource (valueSource ).withValue (newVersion ));
284+ VersionComparator versionComparator = Semver .validate (newVersion , versionPattern ).getValue ();
285+ if (versionComparator == null ) {
286+ return visited ;
287+ }
288+ Optional <String > finalVersion = versionComparator .upgrade (oldVersion != null ? oldVersion : "" , singletonList (newVersion ));
289+ if (finalVersion .isPresent ()) {
290+ String valueSource = initializer .getValueSource () == null || oldVersion == null ? initializer .getValueSource () : initializer .getValueSource ().replace (oldVersion , newVersion );
291+ return visited .withInitializer (initializer .withValueSource (valueSource ).withValue (finalVersion .get ()));
292+ }
269293 }
270294 }
271295 return visited ;
0 commit comments