plugins {
    id 'java-library'
    id 'maven-publish'
    alias catalog.plugins.kotlin.jvm
}

configurations {

    bundle {
        canBeResolved = false
        canBeConsumed = false
        transitive = true
    }

    filteredBundle {
        canBeResolved = true
        canBeConsumed = false
        transitive = true

        extendsFrom bundle

        resolutionStrategy {
            dependencies {
                exclude group: 'org.slf4j', module: 'slf4j-api'
                exclude group: 'org.jetbrains.kotlin', module: 'kotlin-stdlib'
                exclude group: 'org.jetbrains', module: 'annotations'
            }
        }
    }

    release {
        transitive = false
        canBeConsumed = true
        canBeResolved = true
    }

    compileOnly {
        extendsFrom bundle
    }
}

dependencies {
    compileOnly project(':rbcs-common')
    compileOnly project(':rbcs-api')

    compileOnly catalog.netty.transport
    compileOnly catalog.slf4j.api
    compileOnly catalog.kotlin.stdlib.jdk8
    compileOnly catalog.logback.core
    compileOnly catalog.logback.classic

    bundle catalog.opentelemetry.netty.'4'.'1'
    bundle catalog.opentelemetry.sdk.extension.autoconfigure
    bundle catalog.opentelemetry.logback.appender.'1'.'0'
    bundle catalog.opentelemetry.logback.mdc.'1'.'0'
    bundle catalog.opentelemetry.extension.trace.propagators
    bundle catalog.opentelemetry.exporter.otlp
    bundle catalog.opentelemetry.runtime.telemetry
}

Provider<Tar> bundleTask = tasks.register("bundle", Tar) {
    from(tasks.named(JavaPlugin.JAR_TASK_NAME))
    from(configurations.filteredBundle)
    group = BasePlugin.BUILD_GROUP
}

tasks.named(BasePlugin.ASSEMBLE_TASK_NAME) {
    dependsOn(bundleTask)
}

artifacts {
    release(bundleTask)
}

publishing {
    publications {
        maven(MavenPublication) {
            artifact bundleTask
        }
    }
}
