2
2
* Copyright 2014-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
3
3
*/
4
4
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
+
5
11
plugins {
6
12
`kotlin- dsl`
7
13
}
@@ -16,3 +22,84 @@ dependencies {
16
22
kotlin {
17
23
jvmToolchain(21 )
18
24
}
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\n fun Logger." , " \n\n private fun Logger." )
90
+ .replace(
91
+ " */\n abstract class EmbeddedKotlinPlugin" ,
92
+ " */\n internal abstract class EmbeddedKotlinPlugin"
93
+ )
94
+ )
95
+ }
96
+ }
97
+ }
98
+ }
99
+
100
+ sourceSets {
101
+ main {
102
+ kotlin.srcDir(suppressGradlePluginVersionWarning)
103
+ }
104
+ }
105
+ // endregion
0 commit comments