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

def versionCode = 1
def versionName = "0.0.1.011"

android {
    namespace 'cn.org.bjca.trust.push'
    compileSdk 33

    defaultConfig {
        minSdk 24
        targetSdk 33

        buildConfigField("int", "versionCode", "${versionCode}")
        buildConfigField("String", "versionName", "\"${versionName}\"")

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        consumerProguardFiles "consumer-rules.pro"
    }

    buildTypes {
        debug {
            // 开启混淆
            minifyEnabled true
            // Zipalign压缩优化
            zipAlignEnabled true

            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
        release {
            // 开启混淆
            minifyEnabled true
            // Zipalign压缩优化
            zipAlignEnabled true

            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_11
        targetCompatibility JavaVersion.VERSION_11
    }
    kotlinOptions {
        jvmTarget = '11'
    }
    publishing {
        multipleVariants {
            withSourcesJar()
            withJavadocJar()
            allVariants()
        }
    }
}
dependencies {
    compileOnly  fileTree(dir: 'libs',includes: ['*.jar','*.aar'])
    implementation 'androidx.core:core-ktx:1.7.0'
    implementation 'androidx.appcompat:appcompat:1.4.1'
    implementation 'com.google.android.material:material:1.5.0'
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'

    //数据库相关
    implementation("androidx.room:room-runtime:2.5.0")
    kapt("androidx.room:room-compiler:2.5.0")
//    implementation("androidx.room:room-ktx:2.5.0")

    //添加mqtt 2个包
    implementation 'org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.2.5'
    implementation 'org.eclipse.paho:org.eclipse.paho.android.service:1.1.1'

    //gson
    implementation 'com.google.code.gson:gson:2.9.0'

    // 小米推送
//    implementation (name: 'MiPush_SDK_Client_5_3_0-C_3rd', ext: 'aar')

    // 华为推送
    implementation 'com.huawei.hms:push:6.9.0.300'




}
// 这个是把源码打入aar包中的任务
task sourceJar(type: Jar) {
    archiveClassifier.set('sources')
    from android.sourceSets.main.java.srcDirs
}

/**
 * 上传aar到仓库
 */
afterEvaluate {
    publishing {
        publications {
            release(MavenPublication) {
                groupId = 'cn.org.bjca.trus'
                artifactId = 'push'
                version = versionName
                // 这里除了有debug 还有release
                from components.release
                // 运行任务，把源码打进去
//                artifact sourceJar
            }
        }
        // 添加仓库地址
        repositories {
            maven {
                allowInsecureProtocol(true)
                name = "xuqm"
                url = mavenXuqm.mavenUrl
                credentials {
                    username(mavenXuqm.username)
                    password(mavenXuqm.password)
                }
            }
            maven {
                allowInsecureProtocol(true)
                name = "szyx"
                url = mavenSzyx.mavenUrl
                credentials {
                    username(mavenSzyx.username)
                    password(mavenSzyx.password)
                }
            }
        }
    }
}
