Use excludedSources in AndroidPluginIntegration #2503
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
We're seeing an issue in our internal use with KSP that's leading to a circular dependency. Similar to the integration test I've written to go with this change, we have a task that generates code but relies on the output of the KSP task before it runs. We do not need KSP to perform and work on the code generated from our task, so we used the
excludedSources
API.The issue is that in the
AndroidPluginIntegration
class, Android Sources are being added to the source and dependencies of the KSP task without filtering against theexcludedSources
set. This means that a task added to the Android Sources via an API likeSourceDirectories.addGeneratedSourceDirectory()
cannot currently be excluded from KSP.This PR adds logic to that filter in
AndroidPluginIntegration
that has it respect sources added toexcludedSources
, allowing us to break the circular dependency.excludedSources prevents KSP tasks from taking dependencies on any task that is added to the list in an effort to prevent circular dependencies. However, if an output is added via Android Gradle Plugin's APIs, KSP can still end up with a dependency on the task that generates the output, potentially leading to a circular dependency.
This change modifies the filter logic for adding outputs of Android projects to respect outputs added to
excludedSources
, which can be used to break the circular dependency at the cost of KSP ignoring the added source.