org.jetbrains.kotlin.gradle.plugin.KotlinCommonPlugin.kt Maven / Gradle / Ivy
/*
* 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.Project
import org.gradle.tooling.provider.model.ToolingModelBuilderRegistry
import org.jetbrains.kotlin.gradle.dsl.*
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinWithJavaTarget
import org.jetbrains.kotlin.gradle.tasks.KotlinTasksProvider
import org.jetbrains.kotlin.gradle.utils.configureExperimentalTryK2
internal open class KotlinCommonPlugin(
registry: ToolingModelBuilderRegistry
) : AbstractKotlinPlugin(KotlinTasksProvider(), registry) {
companion object {
private const val targetName = "common"
}
override fun buildSourceSetProcessor(
project: Project,
compilation: KotlinCompilation<*>
): KotlinSourceSetProcessor<*> =
KotlinCommonSourceSetProcessor(KotlinCompilationInfo(compilation), tasksProvider)
override fun apply(project: Project) {
@Suppress("UNCHECKED_CAST")
val target = project.objects.newInstance(
KotlinWithJavaTarget::class.java,
project,
KotlinPlatformType.common,
targetName,
{
object : HasCompilerOptions {
override val options: KotlinMultiplatformCommonCompilerOptions = project.objects
.newInstance(KotlinMultiplatformCommonCompilerOptionsDefault::class.java)
.configureExperimentalTryK2(project)
}
},
{ compilerOptions: KotlinMultiplatformCommonCompilerOptions ->
object : KotlinMultiplatformCommonOptions {
override val options: KotlinMultiplatformCommonCompilerOptions
get() = compilerOptions
}
}
) as KotlinWithJavaTarget
(project.kotlinExtension as KotlinCommonProjectExtension).target = target
super.apply(project)
}
}