plugins {
    id 'java-library'
    id 'org.jetbrains.kotlin.jvm'
    id 'maven-publish'
    id 'signing'
}

java {
    sourceCompatibility = JavaVersion.VERSION_11
    targetCompatibility = JavaVersion.VERSION_11
    sourceSets.main { java.srcDir("src/api/kotlin") }
    withJavadocJar()
    withSourcesJar()
}

javadoc {
    options.addStringOption("charset", "UTF-8")
    if (JavaVersion.current().isJava9Compatible()) options.addBooleanOption('html5', true)
}

kotlin {
    sourceSets.main { kotlin.srcDir("src/api/kotlin") }
    sourceSets {
        all {
            languageSettings {
                optIn('com.highcapable.yukihookapi.annotation.YukiPrivateApi')
                optIn('com.highcapable.yukihookapi.annotation.YukiGenerateApi')
            }
        }
    }
}

tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach {
    kotlinOptions {
        jvmTarget = 11
        freeCompilerArgs = [
                '-opt-in=com.highcapable.yukihookapi.annotation.YukiPrivateApi',
                '-opt-in=com.highcapable.yukihookapi.annotation.YukiGenerateApi',
                '-Xno-param-assertions',
                '-Xno-call-assertions',
                '-Xno-receiver-assertions'
        ]
    }
}

dependencies {
    // Used 82 API Version
    compileOnly 'de.robv.android.xposed:api:82'
    compileOnly fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'androidx.annotation:annotation:1.3.0'
}

group = rootProject.ext.groupId
version = rootProject.ext.apiVersion

publishing {
    publications {
        mavenJava(MavenPublication) {
            artifactId = 'api'
            from components.java
            pom {
                name = rootProject.ext.repoName
                description = rootProject.ext.repoDescription
                url = rootProject.ext.website
                licenses {
                    license {
                        name = rootProject.ext.licenceName
                        url = rootProject.ext.licenceUrl
                    }
                }
                developers {
                    developer {
                        id = rootProject.ext.devId
                        name = rootProject.ext.devUser
                        email = rootProject.ext.userEmail
                    }
                }
                scm {
                    connection = rootProject.ext.githubConnection
                    developerConnection = rootProject.ext.githubDeveloperConnection
                    url = rootProject.ext.githubUrl
                }
            }
        }
    }
    repositories {
        maven {
            name = rootProject.ext.ossName
            url = rootProject.ext.ossUrl
            credentials {
                username = getFileContent("OSSRH_USERNAME")
                password = getFileContent("OSSRH_PASSWORD")
            }
        }
    }
}

signing {
    sign(publishing.publications.mavenJava)
}