Gradle7.x使用 Maven Publish 插件

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

}

android {
    compileSdk 32

    defaultConfig {
        minSdk 21
        targetSdk 32

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

    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = '1.8'
    }
}

dependencies {

    implementation 'androidx.appcompat:appcompat:1.3.0'
    implementation 'com.google.android.material:material:1.4.0'
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
    api 'com.android.billingclient:billing:4.0.0'
    api 'com.android.billingclient:billing-ktx:4.0.0'
    api 'com.squareup.retrofit2:retrofit:2.9.0'
    //支持Gson解析json數(shù)據(jù)
    api 'com.squareup.retrofit2:converter-gson:2.9.0'
    api 'com.squareup.retrofit2:converter-scalars:2.9.0'
    //支持RxJava返回類型
    api "com.squareup.retrofit2:adapter-rxjava3:2.9.0"
    api "io.reactivex.rxjava3:rxjava:3.1.5"
    api "io.reactivex.rxjava3:rxandroid:3.0.0"

}
task generateSourcesJar(type: Jar) {
    from android.sourceSets.main.java.srcDirs
    classifier 'sources'
}

def versionName = "1.0.3-SNAPSHOT"
def SNAPSHOT_REPOSITORY_URL = "xxxx/repository/maven-snapshots/"
def RELEASE_REPOSITORY_URL = "http://xxxxx/repository/maven-releases/"
afterEvaluate {
    publishing {
        publications {
            Production(MavenPublication) {
                // 使用方引用 implementation 'ai.ut.android:billing:1.0.0'
                from components.release
                groupId = "ai.ut.android"
                artifactId = "billing"
                version = versionName
                // 上傳source,這樣使用放可以看到方法注釋
                artifact generateSourcesJar
            }
        }
        repositories {
            // 定義一個(gè) maven 倉(cāng)庫(kù)
            maven {
                allowInsecureProtocol = true
                // 可以有且僅有一個(gè)倉(cāng)庫(kù)不指定 name 屬性,會(huì)隱式設(shè)置為 Maven
                // 根據(jù) versionName 來判斷倉(cāng)庫(kù)地址
                url = versionName.endsWith('SNAPSHOT') ? SNAPSHOT_REPOSITORY_URL : RELEASE_REPOSITORY_URL
                // 倉(cāng)庫(kù)用戶名密碼
                credentials {
                    username = "XXX"
                    password = "XXXX"
                }
            }
        }
    }
}
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容