Skip to content

Conversation

@hfmehmed
Copy link
Collaborator

@hfmehmed hfmehmed commented Jan 9, 2026

Fixes a circular dependency in KSP when in use with legacy-kapt plugin

KotlinCompile.libraries contains the output classes dir of kapt. Since this is a lazy gradle api, filtering does not remove the task dependency so ksp ends up depending on kapt. KAPT itself depends on KSP so this leads to a circular dependency.

Instead use KotlinCompilation.compileDependencyFiles which only contains the compilation jars. On top we need to add the android bootclasspath (containing android.jar and build tools jar)

Fixes #2743

@hfmehmed hfmehmed force-pushed the update-libraries-input branch 3 times, most recently from 6d4a801 to 9fa3b6b Compare January 11, 2026 22:00
@hfmehmed hfmehmed force-pushed the update-libraries-input branch from 9fa3b6b to 42e23de Compare January 12, 2026 12:22
@hfmehmed hfmehmed requested a review from ting-yuan January 12, 2026 13:39
cfg.libraries.from(
project.files(
Callable {
kotlinCompileProvider.get().libraries.filter {
Copy link
Collaborator

Choose a reason for hiding this comment

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

If KotlinCompile.libraries is going to be removed, do you have a schedule of removing the else part?

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 havent had a chance to think about it yet. There is 2 things that need to be answered:

  • Is the alternative (the if case) a satisfactory replacement for this?
  • Will KGP provide separate API similar to KotlinCompile.libraries but one that will exclude kapt

If KGP implements the new API we can move to it as soon as it is released. Otherwise I believe we need some time (so users can test this) to determine if the alternative really covers all edge cases out there

)
configuration.incoming.artifactView { config ->
config.attributes.attribute(
Attribute.of("artifactType", String::class.java), "android-classes-jar"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Looks like a bug in AGP or KGP to me. Why isn't artifactType properly set in configuration?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

As far as i understand the consumer of a specific configuration needs to define what artifactType they want to consume. So here we have KSP saying please give me the incoming dependencies from this configuration, and i only want to see classes jar even if the dependency contains much more. So i dont think this is a bug on the producer side of this configuration (which is KGP)

@hfmehmed hfmehmed merged commit bced480 into google:main Jan 13, 2026
3 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.

Circular Dependency Between KAPT and KSP with AGP 9 and Legacy KAPT

2 participants