From f633a1af9b5722f84fc3d2c429b7048b22f839ce Mon Sep 17 00:00:00 2001 From: Osip Fatkullin Date: Fri, 15 Nov 2024 16:51:33 +0100 Subject: [PATCH] Disable Gradle Doctor task monitoring by default --- build.gradle.kts | 14 ++++----- buildSrc/build.gradle.kts | 1 + .../conventions.gradleDoctor.gradle.kts | 29 +++++++++++++++++++ gradle.properties | 11 ++++--- gradle/libs.versions.toml | 4 +-- 5 files changed, 44 insertions(+), 15 deletions(-) create mode 100644 buildSrc/src/main/kotlin/conventions.gradleDoctor.gradle.kts diff --git a/build.gradle.kts b/build.gradle.kts index 89f6fc00a9a..72e97f51db5 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -2,10 +2,10 @@ * Copyright 2014-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. */ -import org.jetbrains.dokka.gradle.* -import org.jetbrains.kotlin.gradle.dsl.* -import org.jetbrains.kotlin.gradle.tasks.* -import org.jetbrains.kotlin.konan.target.* +import org.jetbrains.dokka.gradle.DokkaMultiModuleTask +import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension +import org.jetbrains.kotlin.gradle.tasks.KotlinCompilationTask +import org.jetbrains.kotlin.konan.target.HostManager val releaseVersion: String? by extra val eapVersion: String? by extra @@ -56,11 +56,7 @@ apply(from = "gradle/compatibility.gradle") plugins { alias(libs.plugins.dokka) apply false alias(libs.plugins.binaryCompatibilityValidator) - alias(libs.plugins.doctor) -} - -doctor { - enableTestCaching = false + conventions.gradleDoctor } subprojects { diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index 14abb994c83..4df27361f75 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -15,6 +15,7 @@ dependencies { implementation(libs.kotlinter) implementation(libs.develocity) + implementation(libs.gradleDoctor) implementation(libs.ktor.server.default.headers) implementation(libs.ktor.server.netty) diff --git a/buildSrc/src/main/kotlin/conventions.gradleDoctor.gradle.kts b/buildSrc/src/main/kotlin/conventions.gradleDoctor.gradle.kts new file mode 100644 index 00000000000..8577c56b44c --- /dev/null +++ b/buildSrc/src/main/kotlin/conventions.gradleDoctor.gradle.kts @@ -0,0 +1,29 @@ +/* + * Copyright 2014-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. + */ + +import org.gradle.api.services.internal.RegisteredBuildServiceProvider + +plugins { + id("com.osacky.doctor") +} + +doctor { + enableTestCaching = false +} + +// Always monitor tasks on CI, but disable it locally by default with providing an option to opt-in. +// See 'doctor.enableTaskMonitoring' in gradle.properties for details. +val enableTasksMonitoring = CI || + properties.getOrDefault("doctor.enableTaskMonitoring", "false").toString().toBoolean() + +if (!enableTasksMonitoring) { + logger.info("Gradle Doctor task monitoring is disabled.") + gradle.sharedServices.unregister("listener-service") +} + +fun BuildServiceRegistry.unregister(name: String) { + val registration = registrations.getByName(name) + registrations.remove(registration) + (registration.service as RegisteredBuildServiceProvider<*, *>).maybeStop() +} diff --git a/gradle.properties b/gradle.properties index d6373f45ac4..e1567fa070d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -7,9 +7,8 @@ kotlin.code.style=official # config version=3.0.2-SNAPSHOT - -## JVM arguments -# +## Performance +# JVM arguments used to run Gradle Daemon. # Notes: # * You can reduce '-Xmx' downto '6g' or even '4g', but this could lead to OOM on project sync in an IDE # while it might be enough for other tasks. @@ -29,9 +28,13 @@ version=3.0.2-SNAPSHOT # * Reduce '-Dkotlin.daemon.options=autoshutdownIdleSeconds' value to '30' # To save some memory, shutting down Kotlin Daemon used for buildSrc compilation after 30 seconds of idle. # See: https://github.com/gradle/gradle/issues/29331 -# org.gradle.jvmargs=-Xms2g -Xmx8g -XX:+HeapDumpOnOutOfMemoryError -XX:+UseParallelGC -Dfile.encoding=UTF-8 -Dkotlin.daemon.jvm.options=-Xmx512m,Xms256m,-XX:MaxMetaspaceSize=256m,XX:+HeapDumpOnOutOfMemoryError -Dkotlin.daemon.options=autoshutdownIdleSeconds=1800 kotlin.daemon.jvmargs=-Xms512m -Xmx2g -XX:MaxMetaspaceSize=256m -XX:+HeapDumpOnOutOfMemoryError +# Gradle Doctor might increase memory consumption when task monitoring is enabled, so it is disabled by default. +# Some features can't work without task monitoring: +# doctor-negative-savings, doctor-slow-build-cache-connection, doctor-slow-maven-connection +# Issue: https://github.com/runningcode/gradle-doctor/issues/348 +doctor.enableTaskMonitoring=false # gradle org.gradle.daemon=true diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 08713580d6a..a2345a05d14 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -128,8 +128,6 @@ kotlinx-io-core = { module = "org.jetbrains.kotlinx:kotlinx-io-core", version.re kotlinx-browser = { module = "org.jetbrains.kotlinx:kotlinx-browser", version.ref = "kotlinx-browser" } -kotlinter = { module = "org.jmailen.gradle:kotlinter-gradle", version.ref = "ktlint" } - dokka-plugin-versioning = { module = "org.jetbrains.dokka:versioning-plugin", version.ref = "dokka" } netty-handler = { module = "io.netty:netty-handler", version.ref = "netty" } @@ -229,6 +227,8 @@ tomlj = { module = "org.tomlj:tomlj", version.ref = "tomlj" } develocity = { module = "com.gradle:develocity-gradle-plugin", version.ref = "develocity" } develocity-commonCustomUserData = { module = "com.gradle:common-custom-user-data-gradle-plugin", version.ref = "develocity-commonCustomUserData" } +kotlinter = { module = "org.jmailen.gradle:kotlinter-gradle", version.ref = "ktlint" } +gradleDoctor = { module = "com.osacky.doctor:doctor-plugin", version.ref = "gradleDoctor" } [plugins]