ligi ligi - 3 months ago 13
Android Question

maven publish android.library with aar and source jar

can somebody give me a hint on how to use the maven-publish gradle plugin to publish a com.android.library project 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

Answer

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 "source"
}

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

Comments