[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:
committed by
Space Team
parent
001bdc411d
commit
eb238c0da7
+2
-2
@@ -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))
|
||||
|
||||
-14
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user