Skip to content

Fix Gradle source root in included builds and index Java in Android modules - #1045

Open
christoph-sg wants to merge 2 commits into
mainfrom
gradle-sourceroot-android-javac
Open

christoph-sg wants to merge 2 commits into
mainfrom
gradle-sourceroot-android-javac

Conversation

@christoph-sg

Copy link
Copy Markdown
Member

Two Gradle plugin fixes found while indexing real-world projects for the Kotlin Analysis API work (#1044). Neither depends on that work: both apply to the javac plugin and scip-kotlinc as they are on main.

Source root in buildSrc and included builds. ScipGradlePlugin used project.getRootDir() as the source root, which for buildSrc and included builds is their own directory, so their documents got paths relative to it. The init script now passes the CLI's working directory as scipSourceroot. With nowinandroid's build-logic included build:

shard path
before convention/src/main/kotlin/HiltConventionPlugin.kt
after build-logic/convention/src/main/kotlin/HiltConventionPlugin.kt

Java in Android modules (#177). The javac plugin was only attached in java projects. AGP's JavaCompile tasks always get -processorpath from the annotation processor configurations, so in com.android.* projects the plugin jar is now added to annotationProcessor, testAnnotationProcessor and androidTestAnnotationProcessor. With scip-java index -- :timber-sample:compileDebugJavaWithJavac on JakeWharton/timber:

Java documents in timber-sample
before 0
after 4 sources, plus generated BuildConfig and data binding classes

scipCompileAll still doesn't trigger Android compile tasks, so Android variants need an explicit build command.

Verified with GradleBuildToolTest and spotlessCheck.

christoph-sg and others added 2 commits October 26, 2026 17:27
ScipGradlePlugin used project.getRootDir() as the source root for the
javac plugin and scip-kotlinc. buildSrc and included builds have their
own root directory, so their documents got paths relative to it:
kotlinx-datetime's buildSrc/src/main/kotlin/KotlinUserProjectInfra.kt
was indexed as src/main/kotlin/KotlinUserProjectInfra.kt, and
thunderbird-android's included build components/ui/bolt/... as
ui/bolt/...

The init script now passes the CLI's working directory as
scipSourceroot, and the plugin uses it for every build.

Co-authored-by: Amp <amp@ampcode.com>
Amp-Thread-ID: https://ampcode.com/threads/T-01a178a8-3c2c-75e0-bfa6-7417585d4372
The javac plugin was only attached in projects with the `java` plugin,
so Java sources in Android modules were never indexed (#177). Android
JavaCompile tasks always get -processorpath from the variant's
annotation processor configurations, and javac only looks for
-Xplugin plugins there when it is set. In com.android.* projects the
plugin jar is now added to annotationProcessor,
testAnnotationProcessor and androidTestAnnotationProcessor, and
-Xplugin:scip is added to their JavaCompile tasks like for `java`
projects.

The default scipCompileAll still only triggers compileJava, so Android
variants need an explicit build command such as
`scip-java index -- compileDebugJavaWithJavac`.

Co-authored-by: Amp <amp@ampcode.com>
Amp-Thread-ID: https://ampcode.com/threads/T-01a178a8-3c2c-75e0-bfa6-7417585d4372

This branch has not been deployed

No deployments
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