Omar
06/21/2024, 4:05 PMDetected multiple Kotlin daemon sessions at
to appear after starting and completing a new build?
I am upgrading the AndroidX repo to use K2 and encountering a new issue on Mac only. The warning Detected multiple Kotlin daemon sessions at
now appears. Using watch -n 1 ls ../../out/.kotlin/sessions
, I noticed a file is added to out/.kotlin/sessions/
during the configuration stage (buildSrc) and again during the execution stage whenever a compileKotlin
task occurs. The compiler logs show two different session files are created due to two different client alive files (prefixed with kotlin-compiler-in-buildrc
and kotlin-compiler-in-androidx
). However, it seems that kotlin-compiler-in-buildrc
does not clean up after finishingtapchicoma
06/24/2024, 8:01 AMkotlin-dsl
plugin transitively brings own version of KGP for buildSrc
module compilation.Omar
06/24/2024, 12:13 PM./gradlew :buildSrc:dependencies
and the KGP version was 2.0Omar
06/24/2024, 12:14 PMsalive
files used to be stored in different paths for buildSrc vs other modules in the project.
I attached a debugger and added a breakpoint KotlinGradleFinishBuildHandler
for version 1.9.4, and looking at the value of sessionsDir
for buildSrc , it is: /Users/omarismail/Desktop/androidx-main/superproject/frameworks/support/buildSrc/.gradle/kotlin/sessions
and for androidx it is: /Users/omarismail/Desktop/androidx-main/superproject/out/gradle-project-cache/kotlin/sessions
.
In 2.0, the session files are stored in the same location (/Users/omarismail/Desktop/androidx-main/superproject/out/.kotlin/sessions
, causing the error to appear.Omar
06/24/2024, 12:14 PMOmar
06/24/2024, 12:15 PMtapchicoma
06/24/2024, 1:11 PM:buildSrc:buildEnvironment
task to check which KGP version is used to compile buildSrc
Omar
06/24/2024, 1:38 PMclasspath
\--- org.jetbrains.kotlin:kotlin-gradle-plugin:2.0.0
+--- org.jetbrains.kotlin:kotlin-gradle-plugins-bom:2.0.0
| +--- org.jetbrains.kotlin:kotlin-gradle-plugin-api:2.0.0 (c)
| +--- org.jetbrains.kotlin:kotlin-gradle-plugin-model:2.0.0 (c)
| +--- org.jetbrains.kotlin:kotlin-gradle-plugin:2.0.0 (c)
| +--- org.jetbrains.kotlin:kotlin-gradle-plugin-annotations:2.0.0 (c)
| +--- org.jetbrains.kotlin:kotlin-native-utils:2.0.0 (c)
| \--- org.jetbrains.kotlin:kotlin-tooling-core:2.0.0 (c)
+--- org.jetbrains.kotlin:kotlin-gradle-plugin-api:2.0.0
| +--- org.jetbrains.kotlin:kotlin-gradle-plugins-bom:2.0.0 (*)
| +--- org.jetbrains.kotlin:kotlin-gradle-plugin-annotations:2.0.0
| +--- org.jetbrains.kotlin:kotlin-native-utils:2.0.0
| | +--- org.jetbrains.kotlin:kotlin-util-io:2.0.0
| | \--- org.jetbrains.kotlin:kotlin-util-klib:2.0.0
| | \--- org.jetbrains.kotlin:kotlin-util-io:2.0.0
| \--- org.jetbrains.kotlin:kotlin-tooling-core:2.0.0
+--- org.jetbrains.kotlin:kotlin-gradle-plugin-model:2.0.0
| +--- org.jetbrains.kotlin:kotlin-gradle-plugin-api:2.0.0 (*)
| \--- org.jetbrains.kotlin:kotlin-gradle-plugins-bom:2.0.0 (*)
+--- org.jetbrains.kotlin:kotlin-gradle-plugin-idea:2.0.0
| +--- org.jetbrains.kotlin:kotlin-tooling-core:2.0.0
| \--- org.jetbrains.kotlin:kotlin-gradle-plugin-annotations:2.0.0
+--- org.jetbrains.kotlin:kotlin-gradle-plugin-idea-proto:2.0.0
| \--- org.jetbrains.kotlin:kotlin-gradle-plugin-idea:2.0.0 (*)
+--- org.jetbrains.kotlin:kotlin-klib-commonizer-api:2.0.0
| \--- org.jetbrains.kotlin:kotlin-native-utils:2.0.0 (*)
+--- org.jetbrains.kotlin:kotlin-build-tools-api:2.0.0
+--- org.jetbrains.kotlin:kotlin-build-statistics:2.0.0
| +--- org.jetbrains.kotlin:kotlin-build-tools-api:2.0.0
| \--- com.google.code.gson:gson:2.8.9
+--- org.jetbrains.kotlin:kotlin-compiler-runner:2.0.0
| +--- org.jetbrains.kotlin:kotlin-daemon-client:2.0.0
| \--- org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.5.0
+--- org.jetbrains.kotlin:kotlin-util-klib:2.0.0 (*)
\--- org.jetbrains.kotlin:kotlin-compiler-embeddable:2.0.0
+--- org.jetbrains.kotlin:kotlin-daemon-embeddable:2.0.0
\--- org.jetbrains.intellij.deps:trove4j:1.0.20200330
Omar
06/24/2024, 2:08 PM./gradlew :omar:compileKotlin -Pkotlin.project.persistent.dir=dump --no-configuration-cache --rerun-tasks
I get the error "w: Detected multiple Kotlin daemon sessions at"
This only occurs if I set -Pkotlin.project.persistent.dir
.tapchicoma
06/24/2024, 2:08 PMOmar
06/24/2024, 2:09 PMOmar
06/24/2024, 2:13 PMOmar
06/24/2024, 2:13 PM./gradlew :omar:compileKotlin -Pkotlin.project.persistent.dir=dump --no-configuration-cache --rerun-tasks
to reproduce the errorOmar
06/24/2024, 2:25 PMprojectName
as a parameter as well to KotlinGradleBuildServices
and then pass that in to buildHandler.buildFinished
. In that function, we can do the count check and delete only files which contain projectName
https://github.com/JetBrains/kotlin/blob/master/libraries/tools/kotlin-gradle-plug[…]org/jetbrains/kotlin/gradle/plugin/KotlinGradleBuildServices.ktOmar
06/24/2024, 2:25 PMOmar
06/24/2024, 2:48 PMsalive
file. I thought it had the project name as part of the file but that's not true, only the alive
file doestapchicoma
06/24/2024, 4:28 PM-Pkotlin.project.persistent.dir=dump
- still two session files are created, but in different directories:
• buildSrc/.kotlin/sessions/
• .kotlin/sessions
This is happening because Gradle isolates classloaders of different projects and virtually there are two KGP instances used to build the project.
By passing -Pkotlin.project.persistent.dir=dump
you are forcing single location for all projects, so two session files are created in the same dumb/sessions
directory.
This is possibly incorrect detector that tries to ensure only one Kotlin daemon session is used per-project. We need to discuss it further inside the team. Could you also create an issue for this?Omar
06/24/2024, 6:44 PM