[Gradle] Remove maybeRegister in favor of getOrCreate

It had a little use and even this use was causing a problem. Since
inside `maybeRegister {  }` this block Gradle forbids creation of
other entities. Because this block is part of "entity configuration".

So it is recommended to replace with either
* `getOrCreate("foo", invokeWhenCreated = {})`
* or just getOrCreate("foo").apply {}
This commit is contained in:
Anton Lakotka
2023-07-04 16:45:24 +02:00
committed by Space Team
parent 001bdc411d
commit eb238c0da7
2 changed files with 2 additions and 16 deletions
@@ -19,7 +19,7 @@ import org.jetbrains.kotlin.gradle.targets.js.KotlinJsCompilerAttribute
import org.jetbrains.kotlin.gradle.targets.js.KotlinJsTarget
import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrTarget
import org.jetbrains.kotlin.gradle.targets.metadata.isKotlinGranularMetadataEnabled
import org.jetbrains.kotlin.gradle.utils.maybeRegister
import org.jetbrains.kotlin.gradle.utils.getOrCreate
import java.io.File
internal abstract class KotlinSourceSetFactory<T : KotlinSourceSet> internal constructor(
@@ -94,7 +94,7 @@ internal class DefaultKotlinSourceSetFactory(
}
dependencyConfigurationWithMetadata.forEach { (configurationName, metadataName) ->
project.configurations.maybeRegister(metadataName) {
project.configurations.getOrCreate(metadataName).apply {
attributes.attribute(KotlinPlatformType.attribute, KotlinPlatformType.common)
attributes.attribute(Usage.USAGE_ATTRIBUTE, project.usageByName(KotlinUsages.KOTLIN_API))
attributes.attribute(Category.CATEGORY_ATTRIBUTE, project.categoryByName(Category.LIBRARY))
@@ -29,18 +29,4 @@ internal fun <T> NamedDomainObjectContainer<T>.getOrCreate(
}.get() else (if (configure != null) create(name, configure) else create(name)).also { value ->
if (invokeWhenCreated != null) invokeWhenCreated(value)
}
}
internal fun <T> NamedDomainObjectContainer<T>.maybeRegister(
name: String,
configure: (T.() -> Unit)? = null
): NamedDomainObjectProvider<T> {
val entity = if (name in names) {
named(name)
} else {
register(name)
}
if (configure != null) entity.configure(configure)
return entity
}