Skip to content

Conversation

@div-bargali
Copy link
Contributor

@div-bargali div-bargali commented Jan 3, 2026

What's changed?

Added failing unit tests to demonstrate incorrect plugin ordering in settings.gradle[.kts] files when both pluginManagement and buildscript blocks are present.

New tests added:

  • addPluginWithPluginManagementAndBuildscriptBlocks() - Groovy DSL test
  • addPluginWithPluginManagementAndBuildscriptBlocksKotlin() - Kotlin DSL test

These tests currently fail because AddPluginVisitor incorrectly inserts the plugins block between pluginManagement and buildscript, violating Gradle's required ordering.

What's your motivation?

When AddSettingsPlugin is applied to a settings.gradle file containing both pluginManagement and buildscript blocks, it produces invalid Gradle syntax that causes build failures with the error:
only buildscript {} and other plugins {} script blocks are allowed before plugins {} block

Anything in particular you'd like reviewers to focus on?

  • Verify that the test cases accurately represent the expected Gradle ordering requirements
  • Confirm that both Groovy and Kotlin DSL tests properly cover the edge case
  • Review the interpolateResolvedVersionKotlin() helper method for Kotlin tests

Any additional context

This PR includes the failing tests to document the bug before implementing the fix. The fix will be submitted in a follow-up commit.

Impact: This issue affects any project using AddSettingsPlugin on settings files that contain both pluginManagement and buildscript blocks.

Checklist

  • I've added unit tests to cover both positive and negative cases
  • I've read and applied the recipe conventions and best practices
  • I've used the IntelliJ IDEA auto-formatter on affected files

@timtebeek
Copy link
Member

Thanks for getting this started @div-bargali ; At first glance these tests look good to me!

@shanman190
Copy link
Contributor

Both tests also look good to me too!

@timtebeek timtebeek mentioned this pull request Jan 5, 2026
3 tasks
@div-bargali div-bargali marked this pull request as ready for review January 5, 2026 14:56
@div-bargali div-bargali changed the title [WIP] Bug: Incorrect plugin insertion order in settings.gradle with pluginManagement and buildscript Bug: Incorrect plugin insertion order in settings.gradle with pluginManagement and buildscript Jan 5, 2026
@div-bargali
Copy link
Contributor Author

div-bargali commented Jan 5, 2026

Added the fix for the bug @timtebeek.

I also noticed that in the Kotlin script handling section, the AST was parsed incorrectly for the (.kts) files. Due to this, the kotlin login in AddPluginVistor was not working correctly for build.gradle.kts file. I was able to assert that by adding a simple-but-missing test in AddBuildPluginTest class.

I have included the fix for that too in this PR.

…dPluginVisitor.java

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@div-bargali div-bargali requested a review from timtebeek January 5, 2026 15:11
Copy link
Member

@timtebeek timtebeek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for the help here @div-bargali ; that a parallel effort was started accidentally only speaks to that you've picked a worthwhile issue to fix, and I like the approach you took here.

@github-project-automation github-project-automation bot moved this from In Progress to Ready to Review in OpenRewrite Jan 5, 2026
@timtebeek timtebeek added bug Something isn't working recipe Requested Recipe gradle labels Jan 5, 2026
@timtebeek timtebeek merged commit a486cb5 into openrewrite:main Jan 5, 2026
2 checks passed
@github-project-automation github-project-automation bot moved this from Ready to Review to Done in OpenRewrite Jan 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working gradle recipe Requested Recipe

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Bug: Incorrect plugin insertion order in settings.gradle with pluginManagement and buildscript

3 participants