Skip to content

Commit f3aa685

Browse files
committed
Suppress Gradle warning: Unsupported Kotlin plugin version
1 parent 35c2891 commit f3aa685

File tree

2 files changed

+90
-2
lines changed

2 files changed

+90
-2
lines changed

build-settings-logic/build.gradle.kts

+87
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22
* Copyright 2014-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
33
*/
44

5+
@file:Suppress("UnstableApiUsage")
6+
7+
import org.gradle.api.attributes.DocsType.DOCS_TYPE_ATTRIBUTE
8+
import org.gradle.api.attributes.DocsType.SOURCES
9+
import org.gradle.kotlin.dsl.support.*
10+
511
plugins {
612
`kotlin-dsl`
713
}
@@ -16,3 +22,84 @@ dependencies {
1622
kotlin {
1723
jvmToolchain(21)
1824
}
25+
26+
//region Workaround for https://github.com/gradle/gradle/issues/13020
27+
// We have a dependency on Kotlin Gradle Plugin and Gradle _always_ logs an annoying warning because of that:
28+
// Unsupported Kotlin plugin version.
29+
// The warning is always logged, no matter what, and it doesn't ever seem to represent an actual problem.
30+
// So, this code downloads the original EmbeddedKotlinPlugin and disables the warning.
31+
// Because Gradle's classloader is hierarchical, the original class will be replaced.
32+
// Copied from https://github.com/kotest/kotest/pull/4301
33+
34+
val kotlinDslPluginSources: Configuration by configurations.creating {
35+
description = "Download the original Gradle Kotlin DSL plugin source code."
36+
isCanBeConsumed = false
37+
isCanBeResolved = false
38+
isCanBeDeclared = true
39+
isVisible = false
40+
defaultDependencies {
41+
add(project.dependencies.create("org.gradle.kotlin:gradle-kotlin-dsl-plugins:$expectedKotlinDslPluginsVersion"))
42+
}
43+
}
44+
45+
val kotlinDslPluginSourcesResolver: Configuration by configurations.creating {
46+
description = "Resolve files from ${kotlinDslPluginSources.name}."
47+
isCanBeConsumed = false
48+
isCanBeResolved = true
49+
isCanBeDeclared = false
50+
isVisible = false
51+
extendsFrom(kotlinDslPluginSources)
52+
attributes {
53+
attribute(DOCS_TYPE_ATTRIBUTE, objects.named(SOURCES))
54+
}
55+
}
56+
57+
val suppressGradlePluginVersionWarning by tasks.registering {
58+
description = "Download EmbeddedKotlinPlugin.kt and patch it to disable the warning."
59+
60+
val src = kotlinDslPluginSourcesResolver.incoming.files
61+
inputs.files(src).withNormalizer(ClasspathNormalizer::class)
62+
63+
outputs.dir(temporaryDir).withPropertyName("outputDir")
64+
65+
val archives = serviceOf<ArchiveOperations>()
66+
67+
doLast {
68+
val embeddedKotlinPlugin = src.flatMap { s ->
69+
archives.zipTree(s).matching {
70+
include("**/EmbeddedKotlinPlugin.kt")
71+
}
72+
}.firstOrNull()
73+
74+
if (embeddedKotlinPlugin == null) {
75+
// If EmbeddedKotlinPlugin.kt can't be found, then maybe this workaround
76+
// is no longer necessary, or it needs to be updated.
77+
logger.warn("[$path] Could not find EmbeddedKotlinPlugin.kt in $src")
78+
} else {
79+
logger.info("[$path] Patching EmbeddedKotlinPlugin.kt to remove 'Unsupported Kotlin plugin version' warning")
80+
temporaryDir.deleteRecursively()
81+
temporaryDir.mkdirs()
82+
temporaryDir.resolve(embeddedKotlinPlugin.name).apply {
83+
writeText(
84+
embeddedKotlinPlugin.readText()
85+
// This is the key change: converting 'warn' into 'info'.
86+
.replace("\n warn(\n", "\n info(\n")
87+
// Mark internal things as internal to prevent compiler warnings about unused code,
88+
// and to stop them leaking into build scripts.
89+
.replace("\n\nfun Logger.", "\n\nprivate fun Logger.")
90+
.replace(
91+
"*/\nabstract class EmbeddedKotlinPlugin",
92+
"*/\ninternal abstract class EmbeddedKotlinPlugin"
93+
)
94+
)
95+
}
96+
}
97+
}
98+
}
99+
100+
sourceSets {
101+
main {
102+
kotlin.srcDir(suppressGradlePluginVersionWarning)
103+
}
104+
}
105+
//endregion

build-settings-logic/src/main/kotlin/ktorbuild.kotlin-user-project.settings.gradle.kts

+3-2
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ dependencyResolutionManagement {
6868
versionCatalogs {
6969
named("libs") {
7070
kotlinVersion?.let { version("kotlin", it) }
71+
7172
if (buildSnapshotTrain) {
7273
checkNotNull(kotlinVersion) {
7374
"kotlin_version should be specified when building with build_snapshot_train=true"
@@ -84,12 +85,12 @@ gradle.afterProject {
8485
extensions.configure<HasConfigurableKotlinCompilerOptions<*>>("kotlin") {
8586
compilerOptions {
8687
kotlinLanguageVersion?.let { version ->
87-
log("${project.path} : Set Kotlin LV $version")
8888
languageVersion = version
89+
log("$path : Set Kotlin LV $version")
8990
}
9091
kotlinApiVersion?.let { version ->
91-
log("${project.path} : Set Kotlin APIV $version")
9292
apiVersion = version
93+
log("$path : Set Kotlin APIV $version")
9394
}
9495
}
9596
}

0 commit comments

Comments
 (0)