raphw / byte-buddy

Runtime code generation for the Java virtual machine.
https://bytebuddy.net
Apache License 2.0
6.23k stars 804 forks source link

Disabling plugins mentioned in /META-INF/net.bytebuddy/build.plugins from being applied #1561

Closed surbhiia closed 6 days ago

surbhiia commented 10 months ago

Android gradle plugin readme mentions this: "For your compiler plugin to be able of getting recognized as a Byte Buddy compiler project, it must contain its Byte Buddy plugins class names listed in the /META-INF/net.bytebuddy/build.plugins resource file. Currently, this form of discovery is the only option for configuring plugins, but explicit configuration forms will be added in a future version"

I wanted to check if there is any workaround that I can use in the interim until any explicit configuration is available?

The use case I'm looking for it is: If we have multiple plugins (one for each different Http client library - okhttp3, httpURLConnection), but we only want to apply one of these based on some enable/disable flag.

We can perhaps check the flag in: public boolean matches(TypeDescription target) {} method of the plugin but that will be checked for all classes and thereby increasing the build time.

Thanks a lot!

raphw commented 10 months ago

The only one I can think of that I am not uncomfortable with would be a system property. For example, one that contains a regex.

Would that work? If so, could you test it with a local build of Byte Buddy?

surbhiia commented 10 months ago

@raphw Can you please point out the line of code where this regex would be used to decide what plugins apply and also what you had in mind for how the regex system property would look like for example for the case where I have two plugins - okHttp3Plugin and HttpURLPlugin and want to apply one?

raphw commented 10 months ago

I'd try here: https://github.com/raphw/byte-buddy/blob/bba2d6b26d974ce53c94ac5f7814569529bdeff7/byte-buddy-gradle-plugin/android-plugin/src/main/java/net/bytebuddy/build/gradle/android/ByteBuddyAndroidService.java#L131