Remove deprecated ConfigureUtil usages in KotlinProjectExtension
^KT-46019 In Progress
This commit is contained in:
@@ -28,7 +28,7 @@ import org.gradle.kotlin.dsl.*
|
|||||||
import org.gradle.plugin.devel.plugins.JavaGradlePluginPlugin
|
import org.gradle.plugin.devel.plugins.JavaGradlePluginPlugin
|
||||||
import org.jetbrains.dokka.DokkaVersion
|
import org.jetbrains.dokka.DokkaVersion
|
||||||
import org.jetbrains.dokka.gradle.DokkaTask
|
import org.jetbrains.dokka.gradle.DokkaTask
|
||||||
import org.jetbrains.kotlin.gradle.dsl.KotlinSingleTargetExtension
|
import org.jetbrains.kotlin.gradle.dsl.KotlinSingleJavaTargetExtension
|
||||||
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
|
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
|
||||||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
||||||
import plugins.configureDefaultPublishing
|
import plugins.configureDefaultPublishing
|
||||||
@@ -214,7 +214,7 @@ fun Project.wireGradleVariantToCommonGradleVariant(
|
|||||||
wireSourceSet.runtimeClasspath += commonSourceSet.output
|
wireSourceSet.runtimeClasspath += commonSourceSet.output
|
||||||
|
|
||||||
// Allowing to use 'internal' classes/methods from common source code
|
// Allowing to use 'internal' classes/methods from common source code
|
||||||
(extensions.getByName("kotlin") as KotlinSingleTargetExtension).target.compilations.run {
|
(extensions.getByName("kotlin") as KotlinSingleJavaTargetExtension).target.compilations.run {
|
||||||
getByName(wireSourceSet.name).associateWith(getByName(commonSourceSet.name))
|
getByName(wireSourceSet.name).associateWith(getByName(commonSourceSet.name))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -384,7 +384,7 @@ fun Project.reconfigureMainSourcesSetForGradlePlugin(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Allowing to use 'internal' classes/methods from common source code
|
// Allowing to use 'internal' classes/methods from common source code
|
||||||
(extensions.getByName("kotlin") as KotlinSingleTargetExtension).target.compilations.run {
|
(extensions.getByName("kotlin") as KotlinSingleJavaTargetExtension).target.compilations.run {
|
||||||
getByName(SourceSet.TEST_SOURCE_SET_NAME).associateWith(getByName(commonSourceSet.name))
|
getByName(SourceSet.TEST_SOURCE_SET_NAME).associateWith(getByName(commonSourceSet.name))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+29
-26
@@ -5,14 +5,12 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.gradle.dsl
|
package org.jetbrains.kotlin.gradle.dsl
|
||||||
|
|
||||||
import groovy.lang.Closure
|
|
||||||
import org.gradle.api.Action
|
import org.gradle.api.Action
|
||||||
import org.gradle.api.NamedDomainObjectContainer
|
import org.gradle.api.NamedDomainObjectContainer
|
||||||
import org.gradle.api.Project
|
import org.gradle.api.Project
|
||||||
import org.gradle.api.internal.plugins.DslObject
|
import org.gradle.api.internal.plugins.DslObject
|
||||||
import org.gradle.jvm.toolchain.JavaLanguageVersion
|
import org.gradle.jvm.toolchain.JavaLanguageVersion
|
||||||
import org.gradle.jvm.toolchain.JavaToolchainSpec
|
import org.gradle.jvm.toolchain.JavaToolchainSpec
|
||||||
import org.gradle.util.ConfigureUtil
|
|
||||||
import org.jetbrains.kotlin.gradle.plugin.*
|
import org.jetbrains.kotlin.gradle.plugin.*
|
||||||
import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider.Companion.kotlinPropertiesProvider
|
import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider.Companion.kotlinPropertiesProvider
|
||||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinAndroidTarget
|
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinAndroidTarget
|
||||||
@@ -130,32 +128,40 @@ open class KotlinProjectExtension @Inject constructor(project: Project) : Kotlin
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract class KotlinSingleTargetExtension(project: Project) : KotlinProjectExtension(project) {
|
abstract class KotlinSingleTargetExtension<TARGET : KotlinTarget>(project: Project) : KotlinProjectExtension(project) {
|
||||||
abstract val target: KotlinTarget
|
abstract val target: TARGET
|
||||||
|
|
||||||
open fun target(body: Closure<out KotlinTarget>) = ConfigureUtil.configure(body, target)
|
fun target(body: Action<TARGET>) = body.execute(target)
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract class KotlinSingleJavaTargetExtension(project: Project) : KotlinSingleTargetExtension(project) {
|
abstract class KotlinSingleJavaTargetExtension(project: Project) : KotlinSingleTargetExtension<KotlinWithJavaTarget<*>>(project)
|
||||||
abstract override val target: KotlinWithJavaTarget<*>
|
|
||||||
}
|
|
||||||
|
|
||||||
open class KotlinJvmProjectExtension(project: Project) : KotlinSingleJavaTargetExtension(project) {
|
abstract class KotlinJvmProjectExtension(project: Project) : KotlinSingleJavaTargetExtension(project) {
|
||||||
override lateinit var target: KotlinWithJavaTarget<KotlinJvmOptions>
|
override lateinit var target: KotlinWithJavaTarget<KotlinJvmOptions>
|
||||||
internal set
|
internal set
|
||||||
|
|
||||||
open fun target(body: KotlinWithJavaTarget<KotlinJvmOptions>.() -> Unit) = target.run(body)
|
open fun target(body: KotlinWithJavaTarget<KotlinJvmOptions>.() -> Unit) = target.run(body)
|
||||||
}
|
}
|
||||||
|
|
||||||
open class Kotlin2JsProjectExtension(project: Project) : KotlinSingleJavaTargetExtension(project) {
|
abstract class Kotlin2JsProjectExtension(project: Project) : KotlinSingleJavaTargetExtension(project) {
|
||||||
override lateinit var target: KotlinWithJavaTarget<KotlinJsOptions>
|
private lateinit var _target: KotlinWithJavaTarget<KotlinJsOptions>
|
||||||
internal set
|
|
||||||
|
override val target: KotlinWithJavaTarget<KotlinJsOptions>
|
||||||
|
get() {
|
||||||
|
if (!::_target.isInitialized) throw IllegalStateException("Extension target is not initialized!")
|
||||||
|
|
||||||
|
return _target
|
||||||
|
}
|
||||||
|
|
||||||
|
internal fun setTarget(target: KotlinWithJavaTarget<KotlinJsOptions>) {
|
||||||
|
_target = target
|
||||||
|
}
|
||||||
|
|
||||||
open fun target(body: KotlinWithJavaTarget<KotlinJsOptions>.() -> Unit) = target.run(body)
|
open fun target(body: KotlinWithJavaTarget<KotlinJsOptions>.() -> Unit) = target.run(body)
|
||||||
}
|
}
|
||||||
|
|
||||||
open class KotlinJsProjectExtension(project: Project) :
|
abstract class KotlinJsProjectExtension(project: Project) :
|
||||||
KotlinSingleTargetExtension(project),
|
KotlinSingleTargetExtension<KotlinJsTargetDsl>(project),
|
||||||
KotlinJsCompilerTypeHolder {
|
KotlinJsCompilerTypeHolder {
|
||||||
lateinit var irPreset: KotlinJsIrSingleTargetPreset
|
lateinit var irPreset: KotlinJsIrSingleTargetPreset
|
||||||
|
|
||||||
@@ -180,16 +186,13 @@ open class KotlinJsProjectExtension(project: Project) :
|
|||||||
|
|
||||||
@Deprecated("Use js() instead", ReplaceWith("js()"))
|
@Deprecated("Use js() instead", ReplaceWith("js()"))
|
||||||
@Suppress("DEPRECATION")
|
@Suppress("DEPRECATION")
|
||||||
override var target: KotlinJsTargetDsl
|
override val target: KotlinJsTargetDsl
|
||||||
get() {
|
get() {
|
||||||
if (_target == null) {
|
if (_target == null) {
|
||||||
js {}
|
js {}
|
||||||
}
|
}
|
||||||
return _target!!
|
return _target!!
|
||||||
}
|
}
|
||||||
set(value) {
|
|
||||||
_target = value
|
|
||||||
}
|
|
||||||
|
|
||||||
override lateinit var defaultJsCompilerType: KotlinJsCompilerType
|
override lateinit var defaultJsCompilerType: KotlinJsCompilerType
|
||||||
|
|
||||||
@@ -261,18 +264,18 @@ open class KotlinJsProjectExtension(project: Project) :
|
|||||||
|
|
||||||
fun js() = js { }
|
fun js() = js { }
|
||||||
|
|
||||||
fun js(compiler: KotlinJsCompilerType, configure: Closure<*>) =
|
fun js(compiler: KotlinJsCompilerType, configure: Action<KotlinJsTargetDsl>) =
|
||||||
js(compiler = compiler) {
|
js(compiler = compiler) {
|
||||||
ConfigureUtil.configure(configure, this)
|
configure.execute(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun js(compiler: String, configure: Closure<*>) =
|
fun js(compiler: String, configure: Action<KotlinJsTargetDsl>) =
|
||||||
js(compiler = compiler) {
|
js(compiler = compiler) {
|
||||||
ConfigureUtil.configure(configure, this)
|
configure.execute(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun js(configure: Closure<*>) = jsInternal {
|
fun js(configure: Action<KotlinJsTargetDsl>) = jsInternal {
|
||||||
ConfigureUtil.configure(configure, this)
|
configure.execute(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated("Use js instead", ReplaceWith("js(body)"))
|
@Deprecated("Use js instead", ReplaceWith("js(body)"))
|
||||||
@@ -290,14 +293,14 @@ open class KotlinJsProjectExtension(project: Project) :
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
open class KotlinCommonProjectExtension(project: Project) : KotlinSingleJavaTargetExtension(project) {
|
abstract class KotlinCommonProjectExtension(project: Project) : KotlinSingleJavaTargetExtension(project) {
|
||||||
override lateinit var target: KotlinWithJavaTarget<KotlinMultiplatformCommonOptions>
|
override lateinit var target: KotlinWithJavaTarget<KotlinMultiplatformCommonOptions>
|
||||||
internal set
|
internal set
|
||||||
|
|
||||||
open fun target(body: KotlinWithJavaTarget<KotlinMultiplatformCommonOptions>.() -> Unit) = target.run(body)
|
open fun target(body: KotlinWithJavaTarget<KotlinMultiplatformCommonOptions>.() -> Unit) = target.run(body)
|
||||||
}
|
}
|
||||||
|
|
||||||
open class KotlinAndroidProjectExtension(project: Project) : KotlinSingleTargetExtension(project) {
|
abstract class KotlinAndroidProjectExtension(project: Project) : KotlinSingleTargetExtension<KotlinAndroidTarget>(project) {
|
||||||
override lateinit var target: KotlinAndroidTarget
|
override lateinit var target: KotlinAndroidTarget
|
||||||
internal set
|
internal set
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -677,7 +677,7 @@ internal open class Kotlin2JsPlugin(
|
|||||||
override fun apply(project: Project) {
|
override fun apply(project: Project) {
|
||||||
val target = KotlinWithJavaTarget<KotlinJsOptions>(project, KotlinPlatformType.js, targetName, { KotlinJsOptionsImpl() })
|
val target = KotlinWithJavaTarget<KotlinJsOptions>(project, KotlinPlatformType.js, targetName, { KotlinJsOptionsImpl() })
|
||||||
|
|
||||||
(project.kotlinExtension as Kotlin2JsProjectExtension).target = target
|
(project.kotlinExtension as Kotlin2JsProjectExtension).setTarget(target)
|
||||||
super.apply(project)
|
super.apply(project)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -135,7 +135,7 @@ class GradleProjectModuleBuilder(private val addInferredSourceSetVisibilityAsExp
|
|||||||
|
|
||||||
val targets = when (extension) {
|
val targets = when (extension) {
|
||||||
is KotlinMultiplatformExtension -> extension.targets.filter { it.name != KotlinMultiplatformPlugin.METADATA_TARGET_NAME }
|
is KotlinMultiplatformExtension -> extension.targets.filter { it.name != KotlinMultiplatformPlugin.METADATA_TARGET_NAME }
|
||||||
is KotlinSingleTargetExtension -> listOf(extension.target)
|
is KotlinSingleTargetExtension<*> -> listOf(extension.target)
|
||||||
else -> return emptyList()
|
else -> return emptyList()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -324,7 +324,7 @@ class KpmGradleModuleVariantResolver : KpmModuleVariantResolver {
|
|||||||
}
|
}
|
||||||
else -> {
|
else -> {
|
||||||
val targets =
|
val targets =
|
||||||
project.multiplatformExtensionOrNull?.targets ?: listOf((project.kotlinExtension as KotlinSingleTargetExtension).target)
|
project.multiplatformExtensionOrNull?.targets ?: listOf((project.kotlinExtension as KotlinSingleTargetExtension<*>).target)
|
||||||
|
|
||||||
val compilation =
|
val compilation =
|
||||||
targets.filterIsInstance<AbstractKotlinTarget>()
|
targets.filterIsInstance<AbstractKotlinTarget>()
|
||||||
|
|||||||
+1
-1
@@ -244,7 +244,7 @@ internal object CompilationSourceSetUtil {
|
|||||||
val kotlinExtension = project.kotlinExtension
|
val kotlinExtension = project.kotlinExtension
|
||||||
val targets = when (kotlinExtension) {
|
val targets = when (kotlinExtension) {
|
||||||
is KotlinMultiplatformExtension -> kotlinExtension.targets
|
is KotlinMultiplatformExtension -> kotlinExtension.targets
|
||||||
is KotlinSingleTargetExtension -> listOf(kotlinExtension.target)
|
is KotlinSingleTargetExtension<*> -> listOf(kotlinExtension.target)
|
||||||
else -> emptyList()
|
else -> emptyList()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -12,7 +12,7 @@ import org.jetbrains.kotlin.gradle.plugin.KotlinTarget
|
|||||||
|
|
||||||
val KotlinProjectExtension.targets: Iterable<KotlinTarget>
|
val KotlinProjectExtension.targets: Iterable<KotlinTarget>
|
||||||
get() = when (this) {
|
get() = when (this) {
|
||||||
is KotlinSingleTargetExtension -> listOf(this.target)
|
is KotlinSingleTargetExtension<*> -> listOf(this.target)
|
||||||
is KotlinMultiplatformExtension -> targets
|
is KotlinMultiplatformExtension -> targets
|
||||||
else -> error("Unexpected 'kotlin' extension $this")
|
else -> error("Unexpected 'kotlin' extension $this")
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -26,7 +26,7 @@ interface SourceSetMappedFragmentLocator {
|
|||||||
companion object {
|
companion object {
|
||||||
fun get(project: Project): SourceSetMappedFragmentLocator = when (project.topLevelExtensionOrNull) {
|
fun get(project: Project): SourceSetMappedFragmentLocator = when (project.topLevelExtensionOrNull) {
|
||||||
is KotlinMultiplatformExtension -> MultiplatformSourceSetMappedFragmentLocator()
|
is KotlinMultiplatformExtension -> MultiplatformSourceSetMappedFragmentLocator()
|
||||||
is KotlinSingleTargetExtension -> error("KPM model mapping is not yet supported in single-platform projects; tried to apply to $project")
|
is KotlinSingleTargetExtension<*> -> error("KPM model mapping is not yet supported in single-platform projects; tried to apply to $project")
|
||||||
else -> error("couldn't provide model mapping utilities for project $project")
|
else -> error("couldn't provide model mapping utilities for project $project")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -79,7 +79,7 @@ internal class KotlinProjectNpmResolver(
|
|||||||
?: error("NpmResolverPlugin should be applied after kotlin plugin")
|
?: error("NpmResolverPlugin should be applied after kotlin plugin")
|
||||||
|
|
||||||
when (kotlin) {
|
when (kotlin) {
|
||||||
is KotlinSingleTargetExtension -> addTargetListeners(kotlin.target)
|
is KotlinSingleTargetExtension<*> -> addTargetListeners(kotlin.target)
|
||||||
is KotlinMultiplatformExtension -> kotlin.targets.all {
|
is KotlinMultiplatformExtension -> kotlin.targets.all {
|
||||||
addTargetListeners(it)
|
addTargetListeners(it)
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -234,7 +234,7 @@ private fun KotlinProjectExtension.buildProjectSettings(): KotlinToolingMetadata
|
|||||||
private fun KotlinProjectExtension.buildProjectTargets(): List<KotlinToolingMetadata.ProjectTargetMetadata> {
|
private fun KotlinProjectExtension.buildProjectTargets(): List<KotlinToolingMetadata.ProjectTargetMetadata> {
|
||||||
val targets = when (this) {
|
val targets = when (this) {
|
||||||
is KotlinMultiplatformExtension -> this.targets.toSet()
|
is KotlinMultiplatformExtension -> this.targets.toSet()
|
||||||
is KotlinSingleTargetExtension -> setOf(this.target)
|
is KotlinSingleTargetExtension<*> -> setOf(this.target)
|
||||||
else -> emptySet()
|
else -> emptySet()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user