(minor) Transform KotlinPlatformType attribute to String, rename entries
* To avoid unexpected effects from the Gradle instantiation mechanisms for attribute values, use a safer String attribute type for the KotlinPlatformType attribute * Rename its entries to keep enum entries naming consistent
This commit is contained in:
+15
-15
@@ -10,43 +10,43 @@ import org.gradle.api.attributes.*
|
||||
import org.gradle.util.GradleVersion
|
||||
import java.io.Serializable
|
||||
|
||||
enum class KotlinPlatformType: Named, Serializable {
|
||||
common, jvm, js, androidJvm, native;
|
||||
enum class KotlinPlatformType(val attributeValue: String): Named, Serializable {
|
||||
COMMON("common"), JVM("jvm"), JS("js"), ANDROID_JVM("androidJvm"), NATIVE("native");
|
||||
|
||||
override fun toString(): String = name
|
||||
override fun getName(): String = name
|
||||
|
||||
class CompatibilityRule : AttributeCompatibilityRule<KotlinPlatformType> {
|
||||
override fun execute(details: CompatibilityCheckDetails<KotlinPlatformType>) = with(details) {
|
||||
if (producerValue == jvm && consumerValue == androidJvm)
|
||||
class CompatibilityRule : AttributeCompatibilityRule<String> {
|
||||
override fun execute(details: CompatibilityCheckDetails<String?>) = with(details) {
|
||||
if (producerValue == JVM.attributeValue && consumerValue == ANDROID_JVM.attributeValue)
|
||||
compatible()
|
||||
|
||||
// Allow the input metadata configuration consume platform-specific artifacts if no metadata is available, KT-26834
|
||||
if (consumerValue == common)
|
||||
if (consumerValue == COMMON.attributeValue)
|
||||
compatible()
|
||||
}
|
||||
}
|
||||
|
||||
class DisambiguationRule : AttributeDisambiguationRule<KotlinPlatformType> {
|
||||
override fun execute(details: MultipleCandidatesDetails<KotlinPlatformType?>) = with(details) {
|
||||
if (candidateValues == setOf(androidJvm, jvm))
|
||||
closestMatch(androidJvm)
|
||||
class DisambiguationRule : AttributeDisambiguationRule<String> {
|
||||
override fun execute(details: MultipleCandidatesDetails<String?>) = with(details) {
|
||||
if (candidateValues == setOf(ANDROID_JVM.attributeValue, JVM.attributeValue))
|
||||
closestMatch(ANDROID_JVM.attributeValue)
|
||||
|
||||
if (common in candidateValues)
|
||||
if (COMMON.attributeValue in candidateValues)
|
||||
// then the consumer requests common or requests no platform-specific artifacts,
|
||||
// so common is the best match, KT-26834
|
||||
closestMatch(common)
|
||||
closestMatch(COMMON.attributeValue)
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
val attribute = Attribute.of(
|
||||
val ATTRIBUTE = Attribute.of(
|
||||
"org.jetbrains.kotlin.platform.type",
|
||||
KotlinPlatformType::class.java
|
||||
String::class.java
|
||||
)
|
||||
|
||||
fun setupAttributesMatchingStrategy(attributesSchema: AttributesSchema) {
|
||||
attributesSchema.attribute(KotlinPlatformType.attribute).run {
|
||||
attributesSchema.attribute(KotlinPlatformType.ATTRIBUTE).run {
|
||||
if (isGradleVersionAtLeast(4, 0)) {
|
||||
compatibilityRules.add(CompatibilityRule::class.java)
|
||||
disambiguationRules.add(DisambiguationRule::class.java)
|
||||
|
||||
Reference in New Issue
Block a user