android maven-publish可用配置,亲测

Posted dounine

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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 = '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是写到配置文件里面的,不会上传
~/.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可用配置,亲测的主要内容,如果未能解决你的问题,请参考以下文章

android maven-publish可用配置,亲测

Android上传私有插件到私有MAVEN-PUBLISH

Gradle maven-publish 不构建独立的 spring-boot 应用程序

android studio使用 maven push 插件上传私有maven - 已成功使用到项目中

android studio使用 maven push 插件上传私有maven - 已成功使用到项目中

android studio使用 maven push 插件上传私有maven - 已成功使用到项目中