apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply from : '../common.gradle'

android {
    defaultConfig {
        minSdkVersion 12
    }

    namespace 'com.hjq.gson.factory'

    android.libraryVariants.configureEach { variant ->
        // aar 输出文件名配置
        variant.outputs.configureEach { output ->
            outputFileName = "${rootProject.name}-${android.defaultConfig.versionName}.aar"
        }
    }
}

afterEvaluate {
    // 排除 BuildConfig.class 和 R.class
    generateReleaseBuildConfig.enabled = false
    generateDebugBuildConfig.enabled = false
    generateReleaseResValues.enabled = false
    generateDebugResValues.enabled = false
}

dependencies {
    // Json 解析框架：https://github.com/google/gson
    // noinspection GradleDependency
    implementation 'com.google.code.gson:gson:2.13.1'
    // Kotlin 反射依赖：用于反射 Kotlin data class 类对象
    implementation 'org.jetbrains.kotlin:kotlin-reflect:1.5.10'
}

// 防止编码问题
tasks.withType(Javadoc).configureEach {
    // prevent Javadoc from failing gradle build：https://stackoverflow.com/questions/35435173/prevent-javadoc-from-failing-gradle-build
    failOnError false
    options.addStringOption('Xdoclint:none', '-quiet')
    options.addStringOption('encoding', 'UTF-8')
    options.addStringOption('charSet', 'UTF-8')
}

tasks.register('sourcesJar', Jar) {
    from android.sourceSets.main.java.srcDirs
    classifier = 'sources'
}

tasks.register('javadoc', Javadoc) {
    source = android.sourceSets.main.java.srcDirs
    classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
    // 排除 Kotlin 相关的类 生成 Java Doc
    // https://github.com/novoda/bintray-release/issues/71
    excludes = ['**/*.kt']
}

tasks.register('javadocJar', Jar) {
    dependsOn javadoc
    classifier = 'javadoc'
    from javadoc.destinationDir
}

artifacts {
    archives javadocJar
    archives sourcesJar
}