plugins {
    id 'java'
    id 'java-library'
    id 'com.github.johnrengelman.shadow' version '8.1.1'
    id 'maven-publish'
}

group = project_group
version = project_version

java {
    toolchain {
        languageVersion = JavaLanguageVersion.of(17)
    }
}

base {
    archivesName = "${project_name}-${common_suffix}"
}

repositories {
    mavenCentral()
}

dependencies {
    // Common 依赖 CommonApi
    api project(':CommonApi')

    implementation 'org.apache.logging.log4j:log4j-core:2.23.1'
    implementation 'org.apache.logging.log4j:log4j-api:2.23.1'
    implementation 'org.apache.logging.log4j:log4j-slf4j2-impl:2.23.1'
    implementation 'org.realityforge.org.jetbrains.annotations:org.jetbrains.annotations:1.7.0'
    implementation 'org.apache.commons:commons-lang3:3.17.0'
    implementation 'com.google.guava:guava:33.3.0-jre'
    implementation 'io.netty:netty-all:4.1.109.Final'
    implementation 'com.google.code.gson:gson:2.10.1'
    implementation 'org.slf4j:slf4j-api:2.0.16'

    testImplementation platform('org.junit:junit-bom:5.10.0')
    testImplementation 'org.junit.jupiter:junit-jupiter'
}

// Sources JAR
task sourcesJar(type: Jar) {
    from sourceSets.main.allSource
    archiveClassifier = 'sources'
}

// Javadoc JAR
task javadocJar(type: Jar) {
    dependsOn javadoc
    from javadoc.destinationDir
    archiveClassifier = 'javadoc'
}

// Shadow JAR: 只把 CommonApi 打包进 Common
shadowJar {
    // 只把 CommonApi 的源代码 + Common 自己的源代码打包
    from sourceSets.main.output            // Common 自己的代码
    from project(':CommonApi').sourceSets.main.output  // CommonApi 的代码

    // 不要包含 runtimeClasspath 的依赖
    configurations = []  // 空数组，不包含其它依赖

    mergeServiceFiles()
    archiveClassifier.set('') // 覆盖默认 jar
}


// 将 shadowJar 绑定到 build
build.dependsOn shadowJar

// Javadoc 配置
javadoc {
    options.encoding = 'UTF-8'
}

// 发布配置
publishing {
    publications {
        mavenJava(MavenPublication) {
            artifact shadowJar
            artifact sourcesJar
            artifact javadocJar
            groupId = project.group.toString()
            artifactId = base.archivesName.get()
            version = project.version.toString()
        }
    }
}
