Compile-only dependencies and Gradle's class decor...
# gradle
o
Compile-only dependencies and Gradle's class decoration seem to form a new type of cat on keyboard Schrödinger's cat: I have a Gradle plugin which conditionally configures the Android Gradle Plugin if present (AGP being a compile-only dependency). With Gradle 9.7.1, my Gradle plugin failed to apply in projects where AGP was not present with
Could not generate a decorated class for type MyPlugin
> com/android/build/api/variant/Variant
But the failure appeared only on GH CI (ubuntu-latest). Locally (also Ubuntu), it was always working. 🙄 Moving the code referencing AGP symbols out of my plugin class fixed it.
h
Do you have a reproducer or a link? IMHO that's a bug, or do you try to overwrite a class and have problems with the file name (case sensitive)?
o
The relevant commit is here: github.com/infix-de/testBalloon/commit/0e5cf6025087… The latest GH action runs show the failure and "fix". Note that this is a branch that will receive force pushes, so commits will change at some point.
h
I just did take a look at the 2_2_0 plugin and the base plugin, but I didn't find the line
withPlugin
, so why do you expect the compile only class to be presented at runtime? 🤔
o
It's all in TestBalloonGradlePlugin_2_2_0. And yes, the compileOnly
Variant
class is not always present at run time, but only in projects which load AGP. I'm guarding the code accessing AGP symbols with a
NoClassDefFoundError
. That mechanism works, it just doesn't always survive Gradle's bytecode manipulation ("decoration").
Oh, and BTW:
withPlugin
reacts (lazily) to a plugin being applied. In this case, it's about a plugin (AGP) being present on the classpath.
a
Is the buildscript classpath consistent in all subprojects? You could be running into this issue https://github.com/gradle/gradle/issues/25616
o
It's an isolated (included) build comprising a single project.
Thanks for the suggestion. If I can get that thing to reproduce locally, I'll try. If it only happens on CI, I'll pass. GitHub is flaky enough these days. [This answer responded to a post suggesting to look into the changes between the affected plugin class files. That post no longer appears.]