openrewrite / rewrite-gradle-plugin

OpenRewrite's Gradle plugin.
Apache License 2.0
60 stars 37 forks source link

[Reminder] Does not parse `.gradle` files. anymore #222

Closed BoykoAlex closed 11 months ago

BoykoAlex commented 1 year ago

This issues is only in the current snapshot and is the result of DefaultProjectParser refactoring - this is just a reminder not to forget this thing.

The switch to OmniParser from ResourceParser resulted in .gradle files not parsed because OmniParser does not have GradleParser therefore this parser with proper build script and settings classpaths needs to be added to the OmniParser. Addition of a parser is inconvenient because it adds a parser at the end which means PlainTextParser would intercept .gradle files...

timtebeek commented 1 year ago

Should we transfer this issue to https://github.com/openrewrite/rewrite-all ? That's where we maintain the OmniParser.

shanman190 commented 1 year ago

It certainly could. I'm guessing that a similar change is coming for the Maven plugin as well.

One aspect that's a bit different from the maven plugin is that the MavenParser is used outside of the resource parsing and the GradleParser was only used within the Gradle plugin. What this means is that historically, these build files would only be parsed when using the respective build plugin. So moving this logic to the OmniParser would have a change in behavior such that it would enabling parsing regardless of build tool.

It's very uncommon for both build tool descriptors to be present, but there is the exception for sample projects. For those, they often have both in an attempt to meet the end user where they are comfortable. By moving this logic from the build plugins to the OmniParser it would actually enable the trait that later on recipes would be able to modify both build descriptors in one pass rather than having to perform two passes, one with each respective build tool.

BoykoAlex commented 1 year ago

I don't think that OmniParser should have GradleParser by default... I think it should be added from Gradle Plugin code with proper classpaths for build script and settings script parsing...

shanman190 commented 1 year ago

Yeah, that's true. It's probably going to be pretty difficult to accurately get those classpath entries from anywhere other than the Gradle plugin.

It should be also be noted though that after a release this morning, this issue is now present in the latest release.

timtebeek commented 1 year ago

@jkschneider the latest rewrite-gradle-plugin release does not parse .gradle files anymore. Is that something you'd like to take on yourself to avoid conflicts as you continue to work on the parsers & plugins?

timtebeek commented 1 year ago

Likely fixed in https://github.com/openrewrite/rewrite-gradle-plugin/commit/099e0a77047fd1b11ba18c5177a3a65ee98ff22b by @sambsnyd

timtebeek commented 11 months ago

Marking this as resolved; thanks all!