Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Android sourcesets as defined by the Android Gradle Plugin #289

Open
wbonnefond opened this issue Mar 14, 2024 · 2 comments · May be fixed by #291
Open

Support Android sourcesets as defined by the Android Gradle Plugin #289

wbonnefond opened this issue Mar 14, 2024 · 2 comments · May be fixed by #291
Labels
enhancement New feature or request

Comments

@wbonnefond
Copy link

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 wbonnefond added the enhancement New feature or request label Mar 14, 2024
@timtebeek
Copy link
Contributor

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 (#290 (comment)) 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

if (subproject.getPlugins().hasPlugin("org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension") ||
subproject.getExtensions().findByName("kotlin") != null && subproject.getExtensions().getByName("kotlin").getClass()
.getCanonicalName().startsWith("org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension")) {
sourceFileStream = sourceFileStream.concat(parseMultiplatformKotlinProject(subproject, exclusions, alreadyParsed, ctx));
}

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.

@wbonnefond
Copy link
Author

wbonnefond commented Mar 14, 2024

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:

@timtebeek timtebeek linked a pull request May 28, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Backlog
Development

Successfully merging a pull request may close this issue.

2 participants