androidgradleandroid-gradle-pluginandroid-librarymaven-publish

Publish an Android library to Maven with AAR and sources JAR


Can somebody give me a hint on how to use the maven-publish Gradle plugin to publish a com.android.library project/module with AAR and source jar? I am able to do this with the old maven plugin - but I would like to use the new maven-publish plugin.


Solution

  • Here's a sample using the new maven-publish plugin.

    apply plugin: 'maven-publish'
    
    task sourceJar(type: Jar) {
        from android.sourceSets.main.java.srcDirs
        classifier "sources"
    }
    
    publishing {
        publications {
            bar(MavenPublication) {
                groupId 'com.foo'
                artifactId 'bar'
                version '0.1'
                artifact(sourceJar)
                artifact("$buildDir/outputs/aar/bar-release.aar")
            }
        }
        repositories {
            maven {
                url "$buildDir/repo"
            }
        }
    }
    

    Publish with ./gradlew clean build publish