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