Introduce KotlinBasePlugin

This interface is a top-level interface for all Kotlin plugins.
Additionally it provides 'pluginVersion' property allowing to get
current applied plugin version

^KT-50869 Fixed
^KT-48008 Fixed
This commit is contained in:
Yahor Berdnikau
2022-04-12 19:56:11 +02:00
committed by Space
parent ca193a89d2
commit 5b45ea9bc9
4 changed files with 25 additions and 10 deletions
@@ -0,0 +1,18 @@
/*
* 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 org.gradle.api.Plugin
import org.gradle.api.Project
/**
* Base Kotlin plugin that is responsible for creating basic build services, configurations,
* and other setup that is common for all Kotlin projects.
*/
interface KotlinBasePlugin : Plugin<Project> {
/** Gets the current version of the Kotlin Gradle plugin. */
val pluginVersion: String
}
@@ -23,9 +23,6 @@ interface KotlinJvmFactory {
/** Instance of DSL object that should be used to configure Kotlin compilation pipeline. */
val kotlinExtension: KotlinTopLevelExtensionConfig
/** Gets the current version of the Kotlin Gradle plugin. */
val pluginVersion: String
/** Creates instance of DSL object that should be used to configure JVM/android specific compilation. */
fun createKotlinJvmOptions(): KotlinJvmOptions
@@ -7,7 +7,6 @@ package org.jetbrains.kotlin.gradle.plugin
import org.gradle.api.Project
import org.gradle.api.file.FileCollection
import org.gradle.api.logging.Logging
import org.gradle.api.provider.Provider
import org.gradle.api.tasks.TaskProvider
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmOptions
@@ -21,10 +20,7 @@ import org.jetbrains.kotlin.gradle.tasks.configuration.KaptWithoutKotlincConfig
import org.jetbrains.kotlin.gradle.tasks.configuration.KotlinCompileConfig
/** Plugin that can be used by third-party plugins to create Kotlin-specific DSL and tasks (compilation and KAPT) for JVM platform. */
abstract class KotlinBaseApiPlugin : KotlinBasePlugin(), KotlinJvmFactory {
private val logger = Logging.getLogger(KotlinBaseApiPlugin::class.java)
override val pluginVersion = getKotlinPluginVersion(logger)
abstract class KotlinBaseApiPlugin : DefaultKotlinBasePlugin(), KotlinJvmFactory {
private lateinit var myProject: Project
private val taskCreator = KotlinTasksProvider()
@@ -21,6 +21,7 @@ import org.gradle.api.NamedDomainObjectFactory
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.logging.Logger
import org.gradle.api.logging.Logging
import org.gradle.api.model.ObjectFactory
import org.gradle.tooling.provider.model.ToolingModelBuilderRegistry
import org.jetbrains.kotlin.compilerRunner.registerCommonizerClasspathConfigurationIfNecessary
@@ -59,7 +60,10 @@ import kotlin.reflect.KClass
* Base Kotlin plugin that is responsible for creating basic build services, configurations,
* and other setup that is common for all Kotlin projects.
*/
abstract class KotlinBasePlugin : Plugin<Project> {
abstract class DefaultKotlinBasePlugin : KotlinBasePlugin {
private val logger = Logging.getLogger(DefaultKotlinBasePlugin::class.java)
override val pluginVersion: String = getKotlinPluginVersion(logger)
override fun apply(project: Project) {
val kotlinPluginVersion = project.getKotlinPluginVersion()
@@ -127,7 +131,7 @@ abstract class KotlinBasePlugin : Plugin<Project> {
}
abstract class KotlinBasePluginWrapper : KotlinBasePlugin() {
abstract class KotlinBasePluginWrapper : DefaultKotlinBasePlugin() {
open val projectExtensionClass: KClass<out KotlinTopLevelExtension> get() = KotlinProjectExtension::class