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

Closed
arunkumar9t2 opened this issue Jul 12, 2022 · 8 comments

Comments

@arunkumar9t2
Copy link

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

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

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

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!

@LeonRa
Copy link

LeonRa commented Feb 3, 2023

Hi @danysantiago, just double-checking if there has been any progress here since August, or if another workaround available. Currently seeing the following error:

'annotationProcessor' dependencies won't be recognized as kapt annotation processors. Please change the configuration name to 'kapt' for these artifacts

copybara-service bot pushed a commit that referenced this issue Feb 23, 2023
…avac compile task.

This change also moves the creation of the hiltAnnotationProcessor configuration earlier since creating it during task configuration is not required and can lead to some issues if the configuration contained is locked.

Updated the SPIPluginTest.kt to verify behaviour with KAPT.

Fixes #3464

RELNOTES=N/A
PiperOrigin-RevId: 511799130
@danysantiago
Copy link
Member

Hey - Sorry for dropping this and taking soo long, I was able to find cause and created a change: #3759

The warning is a false positive, indeed if you only have annotationProcessor then during normal KAPT processing the SPI plugin will be missed, but if you have both it should be fine as a workaround, since during KAPT the kapt one will be picked up, while during hiltCompile the annotationProcessor will be discovered, however the KAPT plugin doesn't know this and produces the warning.

Once the fix lands, using only kapt should work.

@LeonRa
Copy link

LeonRa commented Feb 23, 2023

No problem about the delay, life happens! Thank you for the additional background and the fix 🙏

copybara-service bot pushed a commit that referenced this issue Feb 23, 2023
…avac compile task.

This change also moves the creation of the hiltAnnotationProcessor configuration earlier since creating it during task configuration is not required and can lead to some issues if the configuration contained is locked.

Updated the SPIPluginTest.kt to verify behaviour with KAPT.

Fixes #3464

RELNOTES=N/A
PiperOrigin-RevId: 511799130
copybara-service bot pushed a commit that referenced this issue Feb 23, 2023
…avac compile task.

This change also moves the creation of the hiltAnnotationProcessor configuration earlier since creating it during task configuration is not required and can lead to some issues if the configuration contained is locked.

Updated the SPIPluginTest.kt to verify behaviour with KAPT.

Fixes #3464

RELNOTES=N/A
PiperOrigin-RevId: 511799130
copybara-service bot pushed a commit that referenced this issue Feb 23, 2023
…avac compile task.

This change also moves the creation of the hiltAnnotationProcessor configuration earlier since creating it during task configuration is not required and can lead to some issues if the configuration contained is locked.

Updated the SPIPluginTest.kt to verify behaviour with KAPT.

Fixes #3464

RELNOTES=N/A
PiperOrigin-RevId: 511799130
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment