Skip to content

Conversation

hfmehmed
Copy link
Collaborator

@hfmehmed hfmehmed commented Oct 2, 2025

In order to enable built in kotlin we need to able to read AGP (static + generated such as databinding/buildconfig) sources using the new variant api.
Initial approach was to read "sources.java.all". While this contains everything needed it also contained kapt output directory as well as ksp output directory (because of sources.java.addGeneratedSourceDirectory() registeration for purposes of IDE symbol resolution)

Using "sources.kotlin.all" is a better alternative as it still contains all the static and generated sources but it doesnt contains kapt and ksp output which fixes the circular dependency problem.

Experimenting with reading AGP static and generated sources using
sources.kotlin but regirested KSP generated sources to java sources to
avoid circular dependency

kspTaskProvider.configure { task ->
when (task) {
is KspTaskJvm -> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is / should this ever reachable?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose technically you can use builtin kotlin and ksp1
but maybe we should restrict that it never reaches it since ksp1 is deprecated and we dont thoroughly test it

val dir = destinationProperty?.get()?.asFile
sources.filter { dir?.isParentOf(it.dir) != true }
if (project.isAgpBuiltInKotlinUsed() && androidComponent != null) {
val sources = androidComponent.sources.kotlin?.all
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC the first attempt was androidComponent.sources.java.static. Are they the same set of files? In other words, would this approach miss any desired files?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sources.kotlin contains everything that java.static has and more stuff that are generated by AGP such as databinding and build config.

The benefit of using sources.kotlin.all is also that it doesnt contain the ksp output (hence not leading to circular dependency)

@hfmehmed
Copy link
Collaborator Author

hfmehmed commented Oct 6, 2025

I found another use where this does not work. So holding off of merging this until we untangle that

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