Skip to content

Fix binary name computation for default-package classes in the KSP processor - #2129

Merged
copybara-service[bot] merged 1 commit into
mainfrom
test_977860974
Sep 8, 2026
Merged

Fix binary name computation for default-package classes in the KSP processor#2129
copybara-service[bot] merged 1 commit into
mainfrom
test_977860974

Conversation

@copybara-service

Copy link
Copy Markdown
Contributor

Fix binary name computation for default-package classes in the KSP processor

The KSP processor was added a couple of weeks ago, and I found two things in it while reading it against the APT version.

  1. Binary names for classes in the default package are wrong. getBinaryName always strips '.' from the qualified name, but for a root-package class there is no such prefix, so it drops the first character and leaves a stray dot: a provider Foo ends up written as .oo in the service file. The Java AutoServiceProcessor handles the unnamed package explicitly (it just returns the class name), so the KSP side should do the same. This only bites people who put providers in the default package, which is rare, but the generated file is just wrong when it happens.

  2. The generated META-INF/services/ file is an aggregating output but is declared isolating (aggregating=false). Each file collects every @autoservice provider of that interface anywhere in the module, so a provider in a brand-new source file changes it. With aggregating=false, KSP won't invalidate the file when an unrelated new source is added, so on an incremental build a newly added provider never shows up in the service file. Setting aggregating=true tells KSP to regenerate it whenever there's new input.

No test added: the KSP test harness (room3) needs a full KSP/Kotlin compile that I couldn't run in my environment, and the existing tests only cover packaged classes. Both changes are behaviour-preserving for the common packaged case.

Fixes #2128

FUTURE_COPYBARA_INTEGRATE_REVIEW=#2128 from rootkiller6788:fix-autoservice-ksp-default-package-aggregating cf6ade9

…ocessor

The KSP processor was added a couple of weeks ago, and I found two things in it while reading it against the APT version.

1. Binary names for classes in the default package are wrong. getBinaryName always strips '<package>.' from the qualified name, but for a root-package class there is no such prefix, so it drops the first character and leaves a stray dot: a provider Foo ends up written as .oo in the service file. The Java AutoServiceProcessor handles the unnamed package explicitly (it just returns the class name), so the KSP side should do the same. This only bites people who put providers in the default package, which is rare, but the generated file is just wrong when it happens.

2. The generated META-INF/services/<interface> file is an aggregating output but is declared isolating (aggregating=false). Each file collects every @autoservice provider of that interface anywhere in the module, so a provider in a brand-new source file changes it. With aggregating=false, KSP won't invalidate the file when an unrelated new source is added, so on an incremental build a newly added provider never shows up in the service file. Setting aggregating=true tells KSP to regenerate it whenever there's new input.

No test added: the KSP test harness (room3) needs a full KSP/Kotlin compile that I couldn't run in my environment, and the existing tests only cover packaged classes. Both changes are behaviour-preserving for the common packaged case.

Fixes #2128

COPYBARA_INTEGRATE_REVIEW=#2128 from rootkiller6788:fix-autoservice-ksp-default-package-aggregating cf6ade9
PiperOrigin-RevId: 977976344
@copybara-service
copybara-service Bot merged commit 1f74d9a into main Sep 8, 2026
5 checks passed
@copybara-service
copybara-service Bot deleted the test_977860974 branch September 8, 2026 17:10
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.

1 participant