plugins {
    id 'java'
    id 'maven-publish'
    id 'com.github.johnrengelman.shadow' version '8.1.1'
}
group = api_project_group
version = project_version
base {
    archivesName.set("${project_name}-${api_suffix}")
}
java {
    toolchain {
        languageVersion = JavaLanguageVersion.of(17)
    }
}
sourceSets {
    main {
        java {
            srcDirs = ['src/main/java']
        }
        resources {
            srcDirs = ['src/main/resources']
        }
    }
    test {
        java {
            srcDirs = ['src/test/java']
        }
        resources {
            srcDirs = ['src/test/resources']
        }
    }
}

dependencies {
    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 group: 'org.realityforge.org.jetbrains.annotations', name: 'org.jetbrains.annotations', version: '1.7.0'
    implementation group: 'org.apache.commons', name: 'commons-lang3', version: '3.17.0'
    implementation group: 'com.google.guava', name: 'guava', version: '33.3.0-jre'
    implementation group: 'io.netty', name: 'netty-all', version: '4.1.109.Final'
    implementation group: 'com.google.code.gson', name: 'gson', version: '2.10.1'
    testImplementation platform('org.junit:junit-bom:5.10.0')
    testImplementation 'org.junit.jupiter:junit-jupiter'
    implementation group: 'org.slf4j', name: 'slf4j-api', version: '2.0.16'
}
tasks.register('sourcesJar', Jar) {
    archiveClassifier.set('sources')
    from sourceSets.main.allSource
}

tasks.register('javadocJar', Jar) {
    dependsOn(tasks.named("javadoc"))
    archiveClassifier.set('javadoc')
    from(tasks.named("javadoc").get().destinationDir)
}
// 自定义 jar 输出名称
tasks.jar {
    archiveVersion.set(project.version.toString())
    archiveClassifier.set("")
}

tasks.named('sourcesJar', Jar) {
    archiveClassifier.set('sources')
}

tasks.named('javadocJar', Jar) {
    archiveVersion.set(project.version.toString())
    archiveClassifier.set('javadoc')
}

javadoc {
    options.encoding = 'UTF-8'
    options.charSet = 'UTF-8'
}

publishing {
    publications {
        mavenJava(MavenPublication) {
            from components.java
            artifact(tasks.named("sourcesJar"))
            artifact(tasks.named("javadocJar"))
        }
    }
}