import groovy.json.JsonSlurper

plugins {
    id 'com.android.application' version '7.4.1' apply false
    id 'com.android.library' version '7.4.1' apply false
    id 'org.jetbrains.kotlin.android' version '1.8.20' apply false
    id 'com.google.devtools.ksp' version '1.8.20-1.0.10' apply false
}

ext {
    android = [
            compileSdk: 33,
            minSdk    : 21,
            targetSdk : 33
    ]
    app = [
            versionName: 'universal',
            versionCode: 1
    ]
    maven = [
            developer     : [
                    id   : '0',
                    user : 'fankesyooni',
                    email: 'qzmmcn@163.com'
            ],
            repository    : [
                    groupId    : 'com.highcapable.yukihookapi',
                    apiVersion : [
                            name: '1.1.10',
                            code: 43
                    ],
                    name       : 'YukiHookAPI',
                    description: 'An efficient Hook API and Xposed Module solution built in Kotlin.',
                    website    : 'https://github.com/fankes/YukiHookAPI',
                    licence    : [
                            name: 'MIT License',
                            url : 'https://github.com/fankes/YukiHookAPI/blob/master/LICENSE'
                    ]
            ],
            configurations: [
                    githubConnection         : 'scm:git:git://github.com/path/to/repo.git',
                    githubDeveloperConnection: 'scm:git:ssh://github.com/path/to/repo.git',
                    githubUrl                : 'https://github.com/path/to/repo',
                    ossName                  : 'OSSRH',
                    ossUrl                   : 'https://s01.oss.sonatype.org/service/local/staging/deploy/maven2'
            ]
    ]
}

/**
 * 获取 Maven 授权信息 - 用于 Maven 的提交
 * @param childProjectDir 子项目的目录
 * @return [Object]
 */
@SuppressWarnings('unused')
static Object getMavenCredentials(File childProjectDir) {
    def slurper = new JsonSlurper()
    try {
        return slurper.parse(new File("${childProjectDir.getParent()}/.maven/credentials.json"))
    } catch (Throwable ignored) {
        return slurper.parseText('{"username":"-NEEDED-","password":"-NEEDED-"}')
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}