Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,22 @@ private boolean isPluginVersion(Cursor cursor) {
if (!"version".equals(maybeVersion.getSimpleName())) {
return false;
}
// Walk up the method invocation chain to find "plugins" method
// This handles cases like: id(...) version "x.y.z" apply false
// where apply is between version and plugins
Cursor parent = cursor.dropParentUntil(it -> (it instanceof J.MethodInvocation) || it == Cursor.ROOT_VALUE);
if (!(parent.getValue() instanceof J.MethodInvocation)) {
return false;
while (parent.getValue() instanceof J.MethodInvocation) {
J.MethodInvocation parentMethod = parent.getValue();
if ("plugins".equals(parentMethod.getSimpleName())) {
return true;
}
// Continue walking up the chain
parent = parent.dropParentUntil(it -> (it instanceof J.MethodInvocation) || it == Cursor.ROOT_VALUE);
if (parent.getValue() == Cursor.ROOT_VALUE) {
break;
}
}
J.MethodInvocation maybePlugins = parent.getValue();
return "plugins".equals(maybePlugins.getSimpleName());
return false;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,4 +297,43 @@ void upgradePluginVersionInBuildGradleNotProperties() {
)
);
}


@Test
void kotlinDslWithApplyFalse() {
rewriteRun(
spec -> spec.recipe(new UpgradePluginVersion("com.github.johnrengelman.shadow", "7.1.x", null)),
buildGradleKts(
"""
plugins {
id("com.github.johnrengelman.shadow") version "7.1.0" apply false
}
""",
"""
plugins {
id("com.github.johnrengelman.shadow") version "7.1.2" apply false
}
"""
)
);
}

@Test
void groovyDslWithApplyFalse() {
rewriteRun(
spec -> spec.recipe(new UpgradePluginVersion("com.github.johnrengelman.shadow", "7.1.x", null)),
buildGradle(
"""
plugins {
id 'com.github.johnrengelman.shadow' version '7.1.0' apply false
}
""",
"""
plugins {
id 'com.github.johnrengelman.shadow' version '7.1.2' apply false
}
"""
)
);
}
}
Loading