android maven-publish可用配置,亲测

以下是发布到中央nexus仓库的配置
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 = '[email protected]'
                        }
                    }
                    scm {
                        connection = 'scm:git:git://github.com/dounine/sdk.git'
                        developerConnection = 'scm:git:ssh://[email protected]/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是写到配置文件里面的,不会上传
~/.gradle/gradle.properties文件里面

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

执行发布命令即可

gradle clean build publish

你可能感兴趣的:(android maven-publish可用配置,亲测)