plugins {
    id("gradlebuild.portalplugin.kotlin")
    id("gradlebuild.kotlin-dsl-plugin-extensions")
}

description = "Kotlin DSL Gradle Plugins deployed to the Plugin Portal"

group = "org.gradle.kotlin"
version = "6.6.5"

base.archivesName = "plugins"

dependencies {
    compileOnly(projects.baseServices)
    compileOnly(projects.logging)
    compileOnly(projects.coreApi)
    compileOnly(projects.modelCore)
    compileOnly(projects.core)
    compileOnly(projects.languageJvm)
    compileOnly(projects.languageJava)
    compileOnly(projects.loggingApi)
    compileOnly(projects.platformJvm)
    compileOnly(projects.pluginDevelopment)
    compileOnly(projects.kotlinDsl)
    compileOnly(projects.serviceLookup)
    compileOnly(projects.stdlibJavaExtensions)

    compileOnly(libs.slf4jApi)
    compileOnly(libs.inject)
    compileOnly(libs.jspecify)

    api(libs.kotlinStdlib)


    implementation(libs.kotlinGradlePlugin.relaxRestriction())
    implementation(libs.kotlinGradlePluginApi.relaxRestriction())
    implementation(libs.kotlinSamWithReceiver.relaxRestriction())
    implementation(libs.kotlinAssignment.relaxRestriction())


    testImplementation(projects.logging)
    testImplementation(testFixtures(projects.kotlinDsl))
    testImplementation(libs.slf4jApi)
    testImplementation(libs.kotlinReflect) {
        because("mockito-kotlin 1.6 requires kotlin-reflect in 1.0.7, we want to overrule that")
    }
    testImplementation(testLibs.mockitoKotlin)
}

// Note: these dependencies have strict versions, but Gradle currently supports the scenario when higher version of kotlin can be used
fun<T: ExternalModuleDependency> Provider<T>.relaxRestriction() = map {
    it.copy().apply {
        version {
            require(strictVersion)
        }
    }
}

gradleModule {
    requiredRuntimes {
        daemon = true
    }
    computedRuntimes {
        // Auto-generated by `:checkTargetRuntimes --fix`
        daemon = true
    }
}

packageCycles {
    excludePatterns.add("org/gradle/kotlin/dsl/plugins/base/**")
    excludePatterns.add("org/gradle/kotlin/dsl/plugins/precompiled/**")
}

testFilesCleanup.reportOnly = true

val appliedKgpVersion = libs.versions.kotlin.get()

pluginPublish {
    bundledGradlePlugin(
        name = "embeddedKotlin",
        displayName = "Embedded Kotlin Gradle Plugin",
        description = "Applies version `$appliedKgpVersion` of the `org.jetbrains.kotlin.jvm` plugin",
        pluginId = "org.gradle.kotlin.embedded-kotlin",
        pluginClass = "org.gradle.kotlin.dsl.plugins.embedded.EmbeddedKotlinPlugin"
    )

    bundledGradlePlugin(
        name = "kotlinDsl",
        displayName = "Gradle Kotlin DSL Plugin",
        description = "Applies version `$appliedKgpVersion` of the `org.jetbrains.kotlin.jvm` plugin",
        pluginId = "org.gradle.kotlin.kotlin-dsl",
        pluginClass = "org.gradle.kotlin.dsl.plugins.dsl.KotlinDslPlugin"
    )

    bundledGradlePlugin(
        name = "kotlinDslBase",
        displayName = "Gradle Kotlin DSL Base Plugin",
        description = "Applies version `$appliedKgpVersion` of the `org.jetbrains.kotlin.jvm` plugin",
        pluginId = "org.gradle.kotlin.kotlin-dsl.base",
        pluginClass = "org.gradle.kotlin.dsl.plugins.base.KotlinDslBasePlugin"
    )

    bundledGradlePlugin(
        name = "kotlinDslCompilerSettings",
        displayName = "Gradle Kotlin DSL Compiler Settings",
        description = "Applies version `$appliedKgpVersion` of the `org.jetbrains.kotlin.jvm` plugin",
        pluginId = "org.gradle.kotlin.kotlin-dsl.compiler-settings",
        pluginClass = "org.gradle.kotlin.dsl.plugins.dsl.KotlinDslCompilerPlugins"
    )

    bundledGradlePlugin(
        name = "kotlinDslPrecompiledScriptPlugins",
        displayName = "Gradle Kotlin DSL Precompiled Script Plugins",
        description = "Applies version `$appliedKgpVersion` of the `org.jetbrains.kotlin.jvm` plugin",
        pluginId = "org.gradle.kotlin.kotlin-dsl.precompiled-script-plugins",
        pluginClass = "org.gradle.kotlin.dsl.plugins.precompiled.PrecompiledScriptPlugins"
    )
}
