Skip to content

Apply configured styles after auto-detected styles#1116

Draft
timtebeek wants to merge 2 commits intomainfrom
apply-configured-styles-last
Draft

Apply configured styles after auto-detected styles#1116
timtebeek wants to merge 2 commits intomainfrom
apply-configured-styles-last

Conversation

@timtebeek
Copy link
Copy Markdown
Member

  • With Parse more checkstyle rules into OpenRewrite styles. rewrite#6761 changing style merging to "last wins" semantics, configured styles must be applied after auto-detected styles so they take precedence
  • Previously configured styles were set on the Java parser builder before parsing, and auto-detected styles were added to markers after parsing — meaning auto-detected styles were last and would unintentionally override user configuration (e.g.
    checkstyle rules)
  • Now both auto-detected and configured styles are applied together in AbstractRewriteBaseRunMojo, in the correct order: auto-detected first, configured last
  • Removed the now-unnecessary styles parameter from MavenMojoProjectParser#listSourceFiles

With openrewrite/rewrite#6761 changing style merging to "last wins"
semantics, configured styles must be applied after auto-detected styles
so they take precedence. Previously configured styles were set on the
parser (applied first) and auto-detected styles were added after parsing
(applied last), meaning auto-detected styles would unintentionally
override user configuration.

Remove the now-unnecessary styles parameter from
MavenMojoProjectParser#listSourceFiles and instead apply both
auto-detected and configured styles in the correct order within
AbstractRewriteBaseRunMojo.
@timtebeek timtebeek self-assigned this Feb 26, 2026
@github-project-automation github-project-automation bot moved this to In Progress in OpenRewrite Feb 26, 2026
@timtebeek
Copy link
Copy Markdown
Member Author

Would also need to see adjustments downstream in the CLI.

@timtebeek timtebeek marked this pull request as ready for review February 26, 2026 22:57
@timtebeek timtebeek requested a review from sambsnyd February 26, 2026 22:57
@github-project-automation github-project-automation bot moved this from In Progress to Ready to Review in OpenRewrite Feb 26, 2026
.styles(styles)
.logCompilationWarningsAndErrors(false);

// todo, add styles from autoDetect
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Suggested change
// todo, add styles from autoDetect

return listSourceFiles(mavenProject, maven, projectProvenance, Arrays.asList(MAIN, TEST), ctx);
}

public Stream<SourceFile> listSourceFiles(MavenProject mavenProject, Xml.@Nullable Document maven, List<Marker> projectProvenance, List<MavenScope> scopes,
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This method is used by the CLI, and removing the styles here would cause problems there.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

There's some weird interplay here between the Maven plugin detecting styles after and separate from listSourceFiles, whereas the CLI only calls listSourceFiles and itself in a limited capacity loads styles.

Would we need to detect styles as part of listSourceFiles perhaps, and remove the duplicate logic in the CLI? Any ideas here Sam since this follows on from your earlier work?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yeah we should make things consistent between the CLI, gradle plugins, and maven plugins. I believe there is some inconsistency with how styles are treated / autodetected in the CLI and between the two plugins. There is likely some redundancy.

@timtebeek timtebeek marked this pull request as draft February 27, 2026 14:00
@timtebeek
Copy link
Copy Markdown
Member Author

Heard we might sever the reuse of rewrite-maven-plugin in the Moderne CLI, so might just wait for that to land before making changes here, as it will be easier if there's no backwards compatibility across projects.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Ready to Review

Development

Successfully merging this pull request may close these issues.

Style defined in <configLocation> is ignored by OrderImports / RemoveUnusedImports

2 participants