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

Hilt - Dagger SPI plugins are not called since 2.40 due to flipping of enableAggregatingTask to true by default #3464

Open
arunkumar9t2 opened this issue Jul 12, 2022 · 5 comments

Comments

@arunkumar9t2
Copy link

arunkumar9t2 commented Jul 12, 2022

BindingGraphPlugin.visitGraph() is not called in hilt since 2.40 but worked till 2.39.1. Disabling enableAggregatingTask manually via gradle extension fixes the issue.

Repro https://github.com/arunkumar9t2/dagger-spi-issue

@danysantiago
Copy link
Member

danysantiago commented Jul 12, 2022

Thanks for the sample app! If you need a workaround and are willing to have some Gradle script workaround then you can add the SPI plugin dependency to the annotation processor path of the JavaCompile task that Hilt creates when aggregation is turned ON.

You can do this by first creating a config where you'll put the SPI plugins, then find the task and add it to the processor path, in your sample project it would be like this:

configurations {
    spiPlugins
}

dependencies {
    spiPlugins project(":spi-plugin")
}

project.afterEvaluate {
    project.tasks.withType(JavaCompile)
            .matching { it.name.contains("hiltJavaCompile") }
            .configureEach {
                it.options.annotationProcessorPath += project.configurations.getByName("spiPlugins")
            }
}

But note that translating to a bigger project might be trickier if for example you have configuration caching turned on.

@arunkumar9t2
Copy link
Author

arunkumar9t2 commented Jul 13, 2022

Great thanks for sharing that. Fortunately I have been using a gradle plugin to ship my SPI plugin so I could include this fix for hilt versions this issue appears. I will have to investigate to make this config cache compatible.

copybara-service bot pushed a commit that referenced this issue Jul 20, 2022
…e task.

Without including user added dependencies to those configurations, SPI plugins and other processors are not discovered and will not be invoked when running Dagger's ComponentProcessor.

Fixes #3464

RELNOTES=Fix an issue where SPI plugins were not being invoked with Hilt's Gradle Plugin aggregation turned ON.
PiperOrigin-RevId: 461959499
copybara-service bot pushed a commit that referenced this issue Jul 20, 2022
…e task.

Without including user added dependencies to those configurations, SPI plugins and other processors are not discovered and will not be invoked when running Dagger's ComponentProcessor.

Fixes #3464

RELNOTES=Fix an issue where SPI plugins were not being invoked with Hilt's Gradle Plugin aggregation turned ON.
PiperOrigin-RevId: 461959499
@LeonRa
Copy link

LeonRa commented Aug 29, 2022

Just want to touch base here, as it looks like this ticket is now closed. SPI plugins still don't appear to work with the aggregating task on in 2.43.2, though I can confirm that the suggested workaround works for me. I used Arunkumar's sample above to reproduce in isolation. Are things working as expected or is a fix expected in the future?

@danysantiago
Copy link
Member

danysantiago commented Aug 29, 2022

Hey, thanks for checking, looks like the Hilt Gradle plugin is not correctly finding the kapt configurations even though we added a way to find those via name.

You might be able to workaround this by declaring the SPI Plugin in the annotationProcessor config too: annotationProcessor project(":spi-plugin"), which then we'll be correctly used since AGP takes care of making the config accessible per variant.

I'll try to fix the issue for KAPT plugins.

@danysantiago danysantiago reopened this Aug 29, 2022
@LeonRa
Copy link

LeonRa commented Aug 29, 2022

Thanks so much @danysantiago!

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

Successfully merging a pull request may close this issue.

3 participants