plugins {
    id 'com.android.library'
    id 'org.jetbrains.kotlin.android'
    id 'maven-publish'
    id 'signing'
}

android {
    namespace 'com.highcapable.yukireflection'
    compileSdk 33

    defaultConfig {
        minSdk 21
        targetSdk 33

        consumerProguardFiles 'consumer-rules.pro'
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_11
        targetCompatibility JavaVersion.VERSION_11
    }
    kotlinOptions {
        jvmTarget = '11'
        freeCompilerArgs = [
                '-opt-in=com.highcapable.yukireflection.annotation.YukiPrivateApi',
                '-Xno-param-assertions',
                '-Xno-call-assertions',
                '-Xno-receiver-assertions'
        ]
    }
    lintOptions {
        checkReleaseBuilds false
    }
    publishing {
        singleVariant('release') {
            withSourcesJar()
            withJavadocJar()
        }
    }
}

kotlin { sourceSets { all { languageSettings { optIn('com.highcapable.yukireflection.annotation.YukiPrivateApi') } } } }

dependencies {
    implementation 'androidx.core:core-ktx:1.10.0'
    implementation 'androidx.appcompat:appcompat:1.6.1'
}

tasks.register('androidSourcesJar', Jar) {
    archiveClassifier.set('sources')
    from android.sourceSets.main.java.srcDirs
}

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

publishing {
    publications {
        release(MavenPublication) {
            artifactId = 'api'
            artifact "$buildDir/outputs/aar/${project.name}-release.aar"
            artifact androidSourcesJar
            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 {
                def configs = getMavenCredentials(projectDir)
                username = configs.username
                password = configs.password
            }
        }
    }
}

signing { sign publishing.publications }