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

Use reflection for Gradle agent adapters #115

Merged
merged 14 commits into from
Mar 26, 2025
Merged

Conversation

bigdaz
Copy link
Member

@bigdaz bigdaz commented Mar 25, 2025

In order to function correctly when the adapter and the DV plugin are loaded in different
classloaders, we now avoid casting to DV-plugin types when adapting.

By using reflection consistently for all adapting functionality, the Gradle adapter library
should be more robust in the face of different plugin versions and different classloaders.

When merged into the CCUD Gradle Plugin, this should fix gradle/develocity-ci-injection#37

bigdaz added 11 commits March 24, 2025 22:12
`BuildCacheAdapter` and implementations have been replaced by `BuildCacheConfigurationAdapter`.
By using reflection for all property access, we now support configuring 3 different remote
cache implementations with a single reflecting adapter:
- org.gradle.caching.http.HttpBuildCache
- com.gradle.develocity.agent.gradle.buildcache.DevelocityBuildCache
- com.gradle.enterprise.gradleplugin.GradleEnterpriseBuildCache

Also extracted out `ReflectionProperty` utility type for future reflecting adapters.
A single reflecting adapter handles both the com.gradle.enterprise and com.gradle.develocity types:
- com.gradle.scan.plugin.BuildScanDataObfuscation
- com.gradle.develocity.agent.gradle.scan.BuildScanDataObfuscationConfiguration
A single reflecting adapter handles both the com.gradle.enterprise and com.gradle.develocity types:
- com.gradle.develocity.agent.gradle.scan.BuildScanCaptureConfiguration
- com.gradle.scan.plugin.BuildScanExtension
  - Handles versions with `getCapture()` as well as older versions with `isCaptureTaskInputFiles()`
- Methods: tag(), value(), link()
- Properties: termsOfUseUrl, termsOfUseAgree, uploadInBackground

Now have a shared implementation for these methods across all DV/GE extension types.
- background()
- buildFinished()

Method invocation utilities needed to be updated to cope with overloaded methods
like `background(Runnable)` and `background(Action)`.
This completes the migration of all functionality to reflection.
All adapter functions are now implemented via reflection, so casting to specific extension types
is no longer required. This assists with compatibility in mixed-classloader environments.

See gradle/develocity-ci-injectioni#37
@bigdaz bigdaz requested a review from erichaagdev March 25, 2025 04:27
@bigdaz bigdaz marked this pull request as ready for review March 25, 2025 17:59
@bigdaz bigdaz requested a review from pshevche March 25, 2025 17:59
@bigdaz bigdaz requested a review from erichaagdev March 26, 2025 00:01
@bigdaz bigdaz changed the base branch from main to dd/reflection March 26, 2025 14:03
@bigdaz bigdaz merged commit cb0dc6d into gradle:dd/reflection Mar 26, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants