From b5482b3812ce81c57695c6c1a388b2a40ec4e40c Mon Sep 17 00:00:00 2001 From: Alexander Likhachev Date: Thu, 22 Dec 2022 02:45:29 +0100 Subject: [PATCH] [Gradle] Add Gradle 7.4 variant #KT-52490 In Progress --- buildSrc/src/main/kotlin/GradleCommon.kt | 1 + ...dle-plugin-common-configuration.gradle.kts | 7 + ...plugin-dependency-configuration.gradle.kts | 7 + gradle/verification-metadata.xml | 162 ++++++++++++++++++ .../kotlin/gradle/SimpleKotlinGradleIT.kt | 5 +- .../kotlin/gradle/plugin/PluginWrappers.kt | 145 ++++++++++++++++ .../plugin/internal/MppTestReportHelperG74.kt | 43 +++++ 7 files changed, 368 insertions(+), 2 deletions(-) create mode 100644 libraries/tools/kotlin-gradle-plugin/src/gradle74/kotlin/org/jetbrains/kotlin/gradle/plugin/PluginWrappers.kt create mode 100644 libraries/tools/kotlin-gradle-plugin/src/gradle74/kotlin/org/jetbrains/kotlin/gradle/plugin/internal/MppTestReportHelperG74.kt diff --git a/buildSrc/src/main/kotlin/GradleCommon.kt b/buildSrc/src/main/kotlin/GradleCommon.kt index daa0b3e8a8c..fdcafe25f33 100644 --- a/buildSrc/src/main/kotlin/GradleCommon.kt +++ b/buildSrc/src/main/kotlin/GradleCommon.kt @@ -48,6 +48,7 @@ enum class GradlePluginVariant( GRADLE_MIN("main", "6.7", "6.9"), GRADLE_70("gradle70", "7.0", "7.0"), GRADLE_71("gradle71", "7.1", "7.1"), + GRADLE_74("gradle74", "7.4", "7.4"), GRADLE_75("gradle75", "7.5", "7.5"), GRADLE_76("gradle76", "7.6", "7.6"), } diff --git a/buildSrc/src/main/kotlin/gradle-plugin-common-configuration.gradle.kts b/buildSrc/src/main/kotlin/gradle-plugin-common-configuration.gradle.kts index e593e228348..b6f572a5076 100644 --- a/buildSrc/src/main/kotlin/gradle-plugin-common-configuration.gradle.kts +++ b/buildSrc/src/main/kotlin/gradle-plugin-common-configuration.gradle.kts @@ -74,6 +74,13 @@ if (!kotlinBuildProperties.isInJpsBuildIdeaSync) { ) publishShadowedJar(gradle71SourceSet, commonSourceSet) + // Used for Gradle 7.4+ versions + val gradle74SourceSet = createGradlePluginVariant( + GradlePluginVariant.GRADLE_74, + commonSourceSet = commonSourceSet + ) + publishShadowedJar(gradle74SourceSet, commonSourceSet) + // Used for Gradle 7.5+ versions val gradle75SourceSet = createGradlePluginVariant( GradlePluginVariant.GRADLE_75, diff --git a/buildSrc/src/main/kotlin/gradle-plugin-dependency-configuration.gradle.kts b/buildSrc/src/main/kotlin/gradle-plugin-dependency-configuration.gradle.kts index 9f347151b5e..f7445185752 100644 --- a/buildSrc/src/main/kotlin/gradle-plugin-dependency-configuration.gradle.kts +++ b/buildSrc/src/main/kotlin/gradle-plugin-dependency-configuration.gradle.kts @@ -34,6 +34,13 @@ createGradlePluginVariant( isGradlePlugin = false ) +// Used for Gradle 7.4+ versions +createGradlePluginVariant( + GradlePluginVariant.GRADLE_74, + commonSourceSet = commonSourceSet, + isGradlePlugin = false +) + // Used for Gradle 7.5+ versions createGradlePluginVariant( GradlePluginVariant.GRADLE_75, diff --git a/gradle/verification-metadata.xml b/gradle/verification-metadata.xml index 7b0e9caef0a..3b39905b63b 100644 --- a/gradle/verification-metadata.xml +++ b/gradle/verification-metadata.xml @@ -1762,6 +1762,12 @@ + + + + + + @@ -2910,6 +2916,12 @@ + + + + + + @@ -3056,6 +3068,12 @@ + + + + + + @@ -5791,6 +5809,12 @@ + + + + + + @@ -5803,6 +5827,12 @@ + + + + + + @@ -5815,6 +5845,12 @@ + + + + + + @@ -5827,6 +5863,12 @@ + + + + + + @@ -5839,6 +5881,12 @@ + + + + + + @@ -5851,6 +5899,12 @@ + + + + + + @@ -5863,6 +5917,12 @@ + + + + + + @@ -5875,6 +5935,12 @@ + + + + + + @@ -5887,6 +5953,12 @@ + + + + + + @@ -5899,6 +5971,12 @@ + + + + + + @@ -5911,6 +5989,12 @@ + + + + + + @@ -5923,6 +6007,12 @@ + + + + + + @@ -5935,6 +6025,12 @@ + + + + + + @@ -5947,6 +6043,12 @@ + + + + + + @@ -5959,6 +6061,12 @@ + + + + + + @@ -5971,6 +6079,12 @@ + + + + + + @@ -5983,6 +6097,12 @@ + + + + + + @@ -5995,6 +6115,12 @@ + + + + + + @@ -6007,6 +6133,12 @@ + + + + + + @@ -6019,6 +6151,12 @@ + + + + + + @@ -6031,6 +6169,12 @@ + + + + + + @@ -6049,6 +6193,12 @@ + + + + + + @@ -6991,6 +7141,12 @@ + + + + + + @@ -7083,6 +7239,12 @@ + + + + + + diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/SimpleKotlinGradleIT.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/SimpleKotlinGradleIT.kt index 88b1bc95210..9cd9f012d03 100644 --- a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/SimpleKotlinGradleIT.kt +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/SimpleKotlinGradleIT.kt @@ -216,7 +216,7 @@ class SimpleKotlinGradleIT : KGPBaseTest() { @DisplayName("Proper Gradle plugin variant is used") @GradleTestVersions( - additionalVersions = [TestVersions.Gradle.G_7_0, TestVersions.Gradle.G_7_1, TestVersions.Gradle.G_7_4, TestVersions.Gradle.G_7_5], + additionalVersions = [TestVersions.Gradle.G_7_0, TestVersions.Gradle.G_7_1, TestVersions.Gradle.G_7_3, TestVersions.Gradle.G_7_4, TestVersions.Gradle.G_7_5], maxVersion = TestVersions.Gradle.G_7_6 ) @GradleTest @@ -226,7 +226,8 @@ class SimpleKotlinGradleIT : KGPBaseTest() { val expectedVariant = when (gradleVersion) { GradleVersion.version(TestVersions.Gradle.G_7_6) -> "gradle76" GradleVersion.version(TestVersions.Gradle.G_7_5) -> "gradle75" - in GradleVersion.version(TestVersions.Gradle.G_7_1)..GradleVersion.version(TestVersions.Gradle.G_7_4) -> "gradle71" + GradleVersion.version(TestVersions.Gradle.G_7_4) -> "gradle74" + in GradleVersion.version(TestVersions.Gradle.G_7_1)..GradleVersion.version(TestVersions.Gradle.G_7_3) -> "gradle71" GradleVersion.version(TestVersions.Gradle.G_7_0) -> "gradle70" else -> "main" } diff --git a/libraries/tools/kotlin-gradle-plugin/src/gradle74/kotlin/org/jetbrains/kotlin/gradle/plugin/PluginWrappers.kt b/libraries/tools/kotlin-gradle-plugin/src/gradle74/kotlin/org/jetbrains/kotlin/gradle/plugin/PluginWrappers.kt new file mode 100644 index 00000000000..4ca4a55b9dc --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin/src/gradle74/kotlin/org/jetbrains/kotlin/gradle/plugin/PluginWrappers.kt @@ -0,0 +1,145 @@ +/* + * Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.gradle.plugin + +import com.android.build.gradle.BaseExtension +import org.gradle.api.Named +import org.gradle.api.NamedDomainObjectContainer +import org.gradle.api.Project +import org.gradle.api.file.SourceDirectorySet +import org.gradle.api.model.ObjectFactory +import org.gradle.tooling.provider.model.ToolingModelBuilderRegistry +import org.jetbrains.kotlin.gradle.plugin.internal.* +import javax.inject.Inject + +private const val PLUGIN_VARIANT_NAME = "gradle74" + +open class KotlinPluginWrapper @Inject constructor( + registry: ToolingModelBuilderRegistry +) : AbstractKotlinPluginWrapper(registry) { + + override val pluginVariant: String = PLUGIN_VARIANT_NAME + + override fun apply(project: Project) { + project.registerVariantImplementations() + super.apply(project) + } +} + +open class KotlinCommonPluginWrapper @Inject constructor( + registry: ToolingModelBuilderRegistry +) : AbstractKotlinCommonPluginWrapper(registry) { + + override val pluginVariant: String = PLUGIN_VARIANT_NAME + + override fun apply(project: Project) { + project.registerVariantImplementations() + super.apply(project) + } +} + +open class KotlinAndroidPluginWrapper @Inject constructor( + registry: ToolingModelBuilderRegistry +) : AbstractKotlinAndroidPluginWrapper(registry) { + + override val pluginVariant: String = PLUGIN_VARIANT_NAME + + override fun apply(project: Project) { + project.registerVariantImplementations() + super.apply(project) + } +} + +@Suppress("DEPRECATION_ERROR") +open class Kotlin2JsPluginWrapper @Inject constructor( + registry: ToolingModelBuilderRegistry +) : AbstractKotlin2JsPluginWrapper(registry) { + + override val pluginVariant: String = PLUGIN_VARIANT_NAME + + override fun apply(project: Project) { + project.registerVariantImplementations() + super.apply(project) + } +} + +open class KotlinMultiplatformPluginWrapper : AbstractKotlinMultiplatformPluginWrapper() { + + override val pluginVariant: String = PLUGIN_VARIANT_NAME + + override fun apply(project: Project) { + project.registerVariantImplementations() + super.apply(project) + } +} + +open class KotlinJsPluginWrapper : AbstractKotlinJsPluginWrapper() { + + override val pluginVariant: String = PLUGIN_VARIANT_NAME + + override fun apply(project: Project) { + project.registerVariantImplementations() + super.apply(project) + } +} + +open class KotlinPm20PluginWrapper @Inject constructor( + objectFactory: ObjectFactory +) : AbstractKotlinPm20PluginWrapper(objectFactory) { + + override val pluginVariant: String = PLUGIN_VARIANT_NAME + + override fun apply(project: Project) { + project.registerVariantImplementations() + super.apply(project) + } +} + +open class KotlinPlatformJvmPlugin : KotlinPlatformImplementationPluginBase("jvm") { + override fun apply(project: Project) { + project.applyPlugin() + super.apply(project) + } +} + +open class KotlinPlatformJsPlugin : KotlinPlatformImplementationPluginBase("js") { + override fun apply(project: Project) { + @Suppress("DEPRECATION_ERROR") + project.applyPlugin() + super.apply(project) + } +} + +open class KotlinPlatformAndroidPlugin : KotlinPlatformImplementationPluginBase("android") { + override fun apply(project: Project) { + project.applyPlugin() + super.apply(project) + } + + override fun namedSourceSetsContainer(project: Project): NamedDomainObjectContainer<*> = + (project.extensions.getByName("android") as BaseExtension).sourceSets + + override fun addCommonSourceSetToPlatformSourceSet(commonSourceSet: Named, platformProject: Project) { + val androidExtension = platformProject.extensions.getByName("android") as BaseExtension + val androidSourceSet = androidExtension.sourceSets.findByName(commonSourceSet.name) ?: return + val kotlinSourceSet = androidSourceSet.getExtension(KOTLIN_DSL_NAME) + ?: return + kotlinSourceSet.source(getKotlinSourceDirectorySetSafe(commonSourceSet)!!) + } +} + +open class KotlinPlatformCommonPlugin : KotlinPlatformPluginBase("common") { + override fun apply(project: Project) { + warnAboutKotlin12xMppDeprecation(project) + project.applyPlugin() + } +} + +private fun Project.registerVariantImplementations() { + val factories = VariantImplementationFactories.get(gradle) + factories[MppTestReportHelper.MppTestReportHelperVariantFactory::class] = + MppTestReportHelperG74.MppTestReportHelperVariantFactoryG74() +} diff --git a/libraries/tools/kotlin-gradle-plugin/src/gradle74/kotlin/org/jetbrains/kotlin/gradle/plugin/internal/MppTestReportHelperG74.kt b/libraries/tools/kotlin-gradle-plugin/src/gradle74/kotlin/org/jetbrains/kotlin/gradle/plugin/internal/MppTestReportHelperG74.kt new file mode 100644 index 00000000000..d85eacc4e97 --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin/src/gradle74/kotlin/org/jetbrains/kotlin/gradle/plugin/internal/MppTestReportHelperG74.kt @@ -0,0 +1,43 @@ +/* + * Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.gradle.plugin.internal + +import org.gradle.api.internal.tasks.testing.TestDescriptorInternal +import org.gradle.api.internal.tasks.testing.TestResultProcessor +import org.gradle.api.internal.tasks.testing.TestStartEvent +import org.jetbrains.kotlin.gradle.testing.KotlinTestFailure + +internal class MppTestReportHelperG74 : MppTestReportHelper { + internal class MppTestReportHelperVariantFactoryG74 : + MppTestReportHelper.MppTestReportHelperVariantFactory { + override fun getInstance(): MppTestReportHelper = MppTestReportHelperG74() + } + + override fun reportFailure( + results: TestResultProcessor, + id: Any, + failure: KotlinTestFailure, + isAssertionFailure: Boolean, + ) { + results.failure( + id, + failure, + ) + } + + @Suppress("DuplicatedCode") // the delegating processor implements different interfaces with the same code + override fun createDelegatingTestReportProcessor(origin: TestResultProcessor, targetName: String) = + object : TestResultProcessor by origin { + override fun started(test: TestDescriptorInternal, event: TestStartEvent) { + val myTest = object : TestDescriptorInternal by test { + override fun getDisplayName(): String = "${test.displayName}[$targetName]" + override fun getClassName(): String? = test.className?.replace('$', '.') + override fun getClassDisplayName(): String? = test.classDisplayName?.replace('$', '.') + } + origin.started(myTest, event) + } + } +} \ No newline at end of file