rewrite-gradle-plugin icon indicating copy to clipboard operation
rewrite-gradle-plugin copied to clipboard

Support Android sourcesets as defined by the Android Gradle Plugin

Open wbonnefond opened this issue 1 year ago • 2 comments

What problem are you trying to solve?

The OpenRewrite gradle plugin does not work with Android projects because it has no knowledge of sourcesets defined by the Android Gradle Plugin (AGP). When running a recipe on an Android project all source files are parsed as Quark's and recipes have no effect.

Describe the solution you'd like

It would be great if the plugin could support Android projects as they are a big part of the Java and Kotlin ecosystem. Many Android projects are large multi-module gradle projects and OpenRewrite would be a great tool to help with refactors and migrations.

Have you considered any alternatives or workarounds?

As far as I can tell, there isn't a workaround.

Additional context

Are you interested in contributing this feature to OpenRewrite?

I've explored adding support, but I don't have enough context on the inner workings of the plugin to be very effective. But I am willing to work with someone to help validate and test against a large Android project (700+ modules)

wbonnefond avatar Mar 14 '24 00:03 wbonnefond

Hi @wbonnefond ; good seeing you here again & thanks for the offer to help! We should have some rudimentary support already based on this earlier discussion (https://github.com/openrewrite/rewrite-gradle-plugin/issues/290#issuecomment-1996858591) but it's clear from your post that more could be done. From these lines down there's some handling of Kotlin which might help you cross reference to what you have https://github.com/openrewrite/rewrite-gradle-plugin/blob/38e9a29b5aea93847eb118cd2f83164e53a8e125/plugin/src/main/java/org/openrewrite/gradle/isolated/DefaultProjectParser.java#L661-L665

But perhaps it's good to have a minimized example of how you've configured your sourcesets, such that we can work out what needs to be done to support that going forward.

timtebeek avatar Mar 14 '24 08:03 timtebeek

Hey @timtebeek, so this block doesn't actually work for Android gradle modules. They are, by definition, not kotlin multiplatform modules. For android modules it would need to look for one of com.android.library, com.android.application, or com.android.test plugins, and then get the sourcesets from there. Android modules also have a notion of build variants which can have different sourcesets.

This is a very rough WIP. It's been a long time since I've written java code, so I opted to do most of it in kotlin. But it will definitely need to be reworked to reduce duplication with the existing parse code:

  • https://github.com/openrewrite/rewrite-gradle-plugin/pull/291

wbonnefond avatar Mar 14 '24 17:03 wbonnefond

Implemented in https://github.com/openrewrite/rewrite-gradle-plugin/pull/327 Let us know how this works out for you!

sambsnyd avatar Sep 10 '24 05:09 sambsnyd

Hi @wbonnefond ! We'd like to invite you to contribute to the new rewrite-android

  • https://github.com/openrewrite/rewrite-android/issues/1

Hope to see you there!

timtebeek avatar Sep 13 '24 09:09 timtebeek