Publish aar to Maven repository

1. Configure gradle environment variables

1. Create a .bash_gradle file

insert image description here

2. Execute source ~/.bash_gradle, and then execute the command gradle --version, if the configuration is successful, it will output:

insert image description here

2. Build file configuration

apply plugin: 'maven-publish'

def buildNo = System.env.BUILD_NUMBER ? System.env.BUILD_NUMBER : 0
def ver = new Date().format('yy.MM.dd') + '.' + buildNo
publishing {
    repositories {
        maven {
            url 'http://nexus.xxxx.product.com/repository/app'

            credentials {
                username 'xxxx'
                password 'xxxx'
            }
        }
    }

    publications {
        maven(MavenPublication) {
            // 上传到maven使用debug包
            artifact "xxxx-debug.aar"
            groupId 'com.xxx.sdk'
            artifactId project.name
            version ver

            pom.withXml {
                // 添加POM依赖, 需要跟dependencies保持一致
                def dependenciesNode = asNode().appendNode('dependencies')
                def dependencyNode

                dependencyNode = dependenciesNode.appendNode('dependency')
                dependencyNode.appendNode('groupId', 'com.google.android.material')
                dependencyNode.appendNode('artifactId', 'material')
                dependencyNode.appendNode('version', '1.0.0')
            }
        }
    }
}

3. Write script code

insert image description here

4. Execute the script

Execute in the AndroidStudio terminal ./build.shto complete the operation of compiling, packaging and publishing aar to the maven warehouse.

Guess you like

Origin blog.csdn.net/Memory_of_the_wind/article/details/130025765