android maven-publish可用配置,親測(cè)

以下是發(fā)布到中央nexus倉(cāng)庫(kù)的配置
build.gradle

plugins {
    id 'com.android.library'
    id 'kotlin-android'
    id 'maven-publish'
    id 'signing'
}
task sourcesJar(type: Jar) {
    from android.sourceSets.main.java.srcDirs
    archiveClassifier.set("sources")
}
signing {
    sign publishing.publications
}
afterEvaluate {
    publishing {
        publications {
            release(MavenPublication) {
                groupId = 'com.dounine'
                artifactId = 'sdk'
                version = '1.0.0'
                from components.release
                artifact sourcesJar

                pom {
                    name = artifactId
                    description = "android sdk base analyse"
                    url = 'https://github.com/dounine/sdk'
                    licenses {
                        license {
                            name = 'The Apache Software License, Version 2.0'
                            url = 'https://www.apache.org/licenses/LICENSE-2.0.txt'
                        }
                    }
                    developers {
                        developer {
                            id = 'lake'
                            name = 'lake'
                            email = 'amwoqmgo@gmail.com'
                        }
                    }
                    scm {
                        connection = 'scm:git:git://github.com/dounine/sdk.git'
                        developerConnection = 'scm:git:ssh://git@github.com/dounine/sdk.git'
                        url = 'https://github.com/dounine/sdk/'
                    }
                }
            }
        }
        repositories {
            maven {
                def releasesRepoUrl = "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
                def snapshotsRepoUrl = "https://oss.sonatype.org/content/repositories/snapshots/"
                url = version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl
                allowInsecureProtocol(true)
                credentials {
                    username = NEXUS_USERNAME
                    password = NEXUS_PASSWORD
                }
            }
        }
    }
}

android {
    compileSdkVersion 31

    defaultConfig {
        minSdkVersion 21
        targetSdkVersion 31

        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'
    }
}

repositories {
    google()
    mavenCentral()
}


dependencies {
    implementation 'com.alibaba:fastjson:1.2.37'
    implementation 'com.squareup.okhttp3:okhttp:4.9.3'
    implementation 'com.blankj:utilcodex:1.31.0'
    implementation 'androidx.core:core-ktx:1.3.2'
    implementation 'androidx.appcompat:appcompat:1.4.0'
    implementation 'com.google.android.material:material:1.4.0'
    testImplementation 'junit:junit:4.+'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}

NEXUS_USERNAME跟NEXUS_PASSWORD是寫到配置文件里面的,不會(huì)上傳
~/.gradle/gradle.properties文件里面

NEXUS_PASSWORD=abc
NEXUS_USERNAME=abc
signing.keyId=7BDDF87A
signing.password=********
signing.secretKeyRingFile=/Users/lake/.gnupg/secring.gpg

執(zhí)行發(fā)布命令即可

gradle clean build publish
?著作權(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)容