From 4ec48cfb82b5bf1f79e5364f20c3d505e8c8522d Mon Sep 17 00:00:00 2001 From: "Alexander.Likhachev" Date: Mon, 8 May 2023 20:26:15 +0200 Subject: [PATCH] [Gradle] Add Gradle 8.1+ plugin variant --- buildSrc/src/main/kotlin/GradleCommon.kt | 4 +- ...dle-plugin-common-configuration.gradle.kts | 7 + ...plugin-dependency-configuration.gradle.kts | 7 + gradle/verification-metadata.xml | 12 ++ .../kotlin/gradle/plugin/PluginWrappers.kt | 151 ++++++++++++++++++ 5 files changed, 180 insertions(+), 1 deletion(-) create mode 100644 libraries/tools/kotlin-gradle-plugin/src/gradle81/kotlin/org/jetbrains/kotlin/gradle/plugin/PluginWrappers.kt diff --git a/buildSrc/src/main/kotlin/GradleCommon.kt b/buildSrc/src/main/kotlin/GradleCommon.kt index 6a79f8f249a..7659bf1b189 100644 --- a/buildSrc/src/main/kotlin/GradleCommon.kt +++ b/buildSrc/src/main/kotlin/GradleCommon.kt @@ -54,6 +54,7 @@ enum class GradlePluginVariant( GRADLE_75("gradle75", "7.5", "7.5", "https://docs.gradle.org/7.5.1/javadoc/"), GRADLE_76("gradle76", "7.6", "7.6", "https://docs.gradle.org/7.6.1/javadoc/"), GRADLE_80("gradle80", "8.0", "8.0", "https://docs.gradle.org/8.0.2/javadoc/"), + GRADLE_81("gradle81", "8.1", "8.1", "https://docs.gradle.org/8.1.1/javadoc/"), } val commonSourceSetName = "common" @@ -714,7 +715,8 @@ fun Project.configureDokkaPublication( // Gradle 7.6 javadoc does not have published 'package-list' file private fun GradleExternalDocumentationLinkBuilder.addWorkaroundForElementList(pluginVariant: GradlePluginVariant) { if (pluginVariant == GradlePluginVariant.GRADLE_76 || - pluginVariant == GradlePluginVariant.GRADLE_80 + pluginVariant == GradlePluginVariant.GRADLE_80 || + pluginVariant == GradlePluginVariant.GRADLE_81 ) { packageListUrl.set(URL("${pluginVariant.gradleApiJavadocUrl}element-list")) } 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 d563be6c387..830edec15ae 100644 --- a/buildSrc/src/main/kotlin/gradle-plugin-common-configuration.gradle.kts +++ b/buildSrc/src/main/kotlin/gradle-plugin-common-configuration.gradle.kts @@ -101,4 +101,11 @@ if (!kotlinBuildProperties.isInJpsBuildIdeaSync) { commonSourceSet = commonSourceSet ) publishShadowedJar(gradle80SourceSet, commonSourceSet) + + // Used for Gradle 8.1+ versions + val gradle81SourceSet = createGradlePluginVariant( + GradlePluginVariant.GRADLE_81, + commonSourceSet = commonSourceSet + ) + publishShadowedJar(gradle81SourceSet, commonSourceSet) } 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 80cf5d4e5bc..60c0df36314 100644 --- a/buildSrc/src/main/kotlin/gradle-plugin-dependency-configuration.gradle.kts +++ b/buildSrc/src/main/kotlin/gradle-plugin-dependency-configuration.gradle.kts @@ -62,6 +62,13 @@ createGradlePluginVariant( isGradlePlugin = false ) +// Used for Gradle 8.1+ versions +createGradlePluginVariant( + GradlePluginVariant.GRADLE_81, + commonSourceSet = commonSourceSet, + isGradlePlugin = false +) + publishing { publications { register(DEFAULT_MAIN_PUBLICATION_NAME) { diff --git a/gradle/verification-metadata.xml b/gradle/verification-metadata.xml index 3e8e40ecbe9..4c93c49a551 100644 --- a/gradle/verification-metadata.xml +++ b/gradle/verification-metadata.xml @@ -2540,6 +2540,12 @@ + + + + + + @@ -5633,6 +5639,12 @@ + + + + + + diff --git a/libraries/tools/kotlin-gradle-plugin/src/gradle81/kotlin/org/jetbrains/kotlin/gradle/plugin/PluginWrappers.kt b/libraries/tools/kotlin-gradle-plugin/src/gradle81/kotlin/org/jetbrains/kotlin/gradle/plugin/PluginWrappers.kt new file mode 100644 index 00000000000..006aaf1d335 --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin/src/gradle81/kotlin/org/jetbrains/kotlin/gradle/plugin/PluginWrappers.kt @@ -0,0 +1,151 @@ +/* + * 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 = "gradle81" + +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() + } +} + +open class KotlinApiPlugin : KotlinBaseApiPlugin() { + override fun apply(project: Project) { + project.registerVariantImplementations() + super.apply(project) + } +} + +@Suppress("UnusedReceiverParameter") +private fun Project.registerVariantImplementations() { + +}