Publish Kotlin class outputs as Gradle SourceSet outputs so that VSCode (jdt.ls) resolves Java -> Kotlin imports #14355
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.
First time contributor checklist
Contributor checklist
Fixes #1234syntaxVSCode + Gradle + jdt.ls: Publish Kotlin class outputs for IntelliSense analysis
Summary
This patch teaches Gradle to publish Kotlin class output directories as part of each source set’s outputs.
That enables the Eclipse Buildship model, consumed by VSCode’s Java Language Server (jdt.ls),
to include
build/classes/kotlin/{main,test}on the Java classpath.As a result, Java files can resolve symbols defined in Kotlin files within the same module when working in VSCode.
This is a build‑metadata change only; it does not affect runtime behavior, packaging, or Android build artifacts.
Background
When building Signal-Android with VSCode or derivatives, IntelliSense does not find the compiled
Kotlin classes, resulting in thousands of IntelliSense error messages, while the Gradle builds compile just fine.
The reason for this is that VSCode Java uses jdt.ls with Buildship to import Gradle projects. The imported classpath is derived from Gradle source set outputs. By default, these outputs include the Java classes dir (e.g.,
build/classes/java/main) but not the Kotlin classes dir (build/classes/kotlin/main). When Kotlin outputs aren’t surfaced, jdt.ls can’t type‑check Java references to Kotlin, leading to false IntelliSense errors and broken navigation. Publishing the Kotlin outputs viaSourceSetOutput.output.dir(...)fixes this at the model level and works across cleans.What this patch does
In each affected JVM module (
libsignal-serviceandcore-util-jvm), we declare the Kotlin class directories as additional outputs of themainandtestsource sets, and mark thembuiltBythe corresponding Kotlin compile tasks:Scope & impact
so any importer that respects source set outputs benefits.
VSCode setup
Extensions
Workspace settings (typical)
{ "java.import.gradle.enabled": true, "java.import.gradle.wrapper.enabled": true, "java.import.gradle.offline.enabled": false, "java.import.gradle.buildTasks": ["compileKotlin", "classes"], "java.configuration.updateBuildConfiguration": "automatic", "java.compile.nullAnalysis.mode": "disabled" }Repro/verification steps
./gradlew :libsignal-service:clean :libsignal-service:compileKotlin.Note
This patch was created with the help of ChatGPT-5. I have carefully reviewed all the generated code and documentation and do understand the function and purpose of everything in this patch. However, I am not a Gradle expert myself. Hence, I would have never been able to find this solution by myself and cannot determine if this is the most desirable way to do this. There may be better ways to approach this issue.
References
kotlin imports into Java file are unresolved redhat-developer/vscode-java#531
SourceSetOutput(publish additional output dirs):https://docs.gradle.org/current/dsl/org.gradle.api.tasks.SourceSetOutput.html
https://www.eclipse.org/community/eclipse_newsletter/2018/february/buildship.php