All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jetbrains.kotlin.gradle.plugin.ProjectLocalConfigurations.kt Maven / Gradle / Ivy

There is a newer version: 2.0.0-RC3
Show newest version
/*
 * Copyright 2010-2018 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.artifacts.Configuration
import org.gradle.api.attributes.*
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinWithJavaTarget

/**
 * This attribute is registered in the schema only for the case if some 3rd-party consumer or published
 * module still has it or relies on it. The Kotlin Gradle plugin should not add this attribute to any variant.
 * TODO: examine and remove
 */
object ProjectLocalConfigurations {
    val ATTRIBUTE: Attribute = Attribute.of("org.jetbrains.kotlin.localToProject", String::class.java)

    const val PUBLIC_VALUE = "public"

    fun setupAttributesMatchingStrategy(attributesSchema: AttributesSchema) = with(attributesSchema) {
        attribute(ATTRIBUTE) {
            it.compatibilityRules.add(ProjectLocalCompatibility::class.java)
            it.disambiguationRules.add(ProjectLocalDisambiguation::class.java)
        }
    }

    class ProjectLocalCompatibility : AttributeCompatibilityRule {
        override fun execute(details: CompatibilityCheckDetails) {
            details.compatible()
        }
    }

    class ProjectLocalDisambiguation : AttributeDisambiguationRule {
        override fun execute(details: MultipleCandidatesDetails) = with(details) {
            if (candidateValues.contains(PUBLIC_VALUE)) {
                closestMatch(PUBLIC_VALUE)
            }
        }
    }
}

internal fun Configuration.setupAsLocalTargetSpecificConfigurationIfSupported(target: KotlinTarget) {
    // don't setup in old MPP common modules, as their output configurations with KotlinPlatformType attribute would
    // fail to resolve as transitive dependencies of the platform modules, just as we don't mark their
    // `api/RuntimeElements` with the KotlinPlatformType
    if ((target !is KotlinWithJavaTarget<*, *> || target.platformType != KotlinPlatformType.common)) {
        usesPlatformOf(target)
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy