apply plugin: 'com.android.library'
apply plugin: 'maven-publish'

android {
    compileSdkVersion 28

    defaultConfig {
        minSdkVersion 17
        versionCode 1000
        versionName "10.0"
    }

    // 支持 Java JDK 8
    compileOptions {
        targetCompatibility JavaVersion.VERSION_1_8
        sourceCompatibility JavaVersion.VERSION_1_8
    }

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

afterEvaluate {
    // 排除 BuildConfig.class
    generateReleaseBuildConfig.enabled = false
    generateDebugBuildConfig.enabled = false
}

dependencies {
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support:design:28.0.0'
    // noinspection GradleDependency
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'

    // ShapeDrawable：https://github.com/getActivity/ShapeDrawable
    implementation 'com.github.getActivity:ShapeDrawable:3.3'
}

// 防止编码问题
tasks.withType(Javadoc).configureEach {
    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))
}

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

artifacts {
    archives javadocJar
    archives sourcesJar
}

// Jitpack 构建配置
publishing {
    publications {
        release(MavenPublication) {
            groupId = 'com.github.getActivity'
            artifactId = "${rootProject.name}"
            version = "${android.defaultConfig.versionName}"

            afterEvaluate {
                from components.release
            }
        }
    }
}