Skip to content

[AGP] Register generated kotlin sources with java source set - #2707

Merged
hfmehmed merged 3 commits into
google:mainfrom
hfmehmed:agp-generated-kotlin-sources
Nov 24, 2025
Merged

[AGP] Register generated kotlin sources with java source set#2707
hfmehmed merged 3 commits into
google:mainfrom
hfmehmed:agp-generated-kotlin-sources

Conversation

@hfmehmed

@hfmehmed hfmehmed commented Nov 21, 2025

Copy link
Copy Markdown
Collaborator

Intially we registered java output folder with java sourceset and kotlin output folder with kotlin sourceset. Two reasons for this:

  1. It seemed like the right way to model things
  2. We could only register one directory with one sourcset (registering kotlin output with java sourcset would override the previous registration)

Number 2 is fixed in AGP 9.0.0-alpha14.

However, it turns out number 1 is problematic. Registering with kotlin sourceset ends up in a circular task dependency with built in kotlin feature enabled.

At the moment, we avoid the circular exception because we look at all the task dependencies of the kotlin sourceset and exclude the ksp task. But this is a project isolation breaking logic which we need to remove at some point.

The flow looks like the following more or less:
KSP task -> register kotlin output with kotlin.sources -> kotlin.sources flows into kotlinCompilation.defaultSourceSet.kotlin.srcDirs() this happens in AGP built in kotlin -> kotlin.srcDirs() is an input to ksp task leading to the circularlity.

@hfmehmed
hfmehmed requested a review from ting-yuan November 21, 2025 15:46
@hfmehmed
hfmehmed force-pushed the agp-generated-kotlin-sources branch 2 times, most recently from a5e0e76 to 8a0e947 Compare November 21, 2025 20:54
@hfmehmed
hfmehmed force-pushed the agp-generated-kotlin-sources branch from 8a0e947 to 7fda891 Compare November 24, 2025 14:41
@hfmehmed
hfmehmed merged commit 354336d into google:main Nov 24, 2025
4 of 5 checks 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

Development

Successfully merging this pull request may close these issues.

2 participants