This guide implies that you are using simple security model that is based on uniqueness of URLs. If you are using HTTP Basic Auth then please read a corresponding guide

Help / Android + URL Unique private maven repository


You can use any maven compatible repository (including myMavenRepo) to publish / consume your public / private aar files. There are a few different ways to publish your Android library to private maven repository. This article is based on the following script but you are free to use any other technology like android-maven-publish plugin.


By default our service uses very simple security model - we create unique read/write URL for each user. But this approach has its limitations - anyone who knows your URL can access your data. Because of that putting those URLs in to your build.gradle file directly will be insecure. To solve this problem you can store repository URL in ~/.gradle/ as we do in examples below.

Get more info: official documentation, stackoverflow question

Consuming artifacts

To consume artifacts from your private repository you can use read or write URLs.

  1. 1. Add myMavenRepoReadUrl=${repositoryURL} to file ~/.gradle/, replace ${repositoryURL} with read or write URL of your repository.
  2. 2. Modify /path/to/project/build.gradle file to consume artifacts:
  3. repositories {
        maven {
            url myMavenRepoReadUrl

Publishing artifacts

To publish data to repository you can use only write URL

  1. 1. Add myMavenRepoWriteUrl=${writeURL} to file ~/.gradle/, replace ${writeURL} with write URL of your repository
  2. 2. Modify /path/to/project/build.gradle file to configure publish task:
  3. apply plugin: 'maven-publish'
    publishing {
        repositories {
            maven {
                url myMavenRepoWriteUrl
        publications {
            maven(MavenPublication) {
                groupId ''
                artifactId 'custom-artifact'
                version = '0.1-SNAPSHOT'
                artifact bundleReleaseAar
                artifact androidJavadocsJar
                artifact androidSourcesJar
                pom.withXml {
                    final dependenciesNode = asNode().appendNode('dependencies')
                    ext.addDependency = { Dependency dep, String scope ->
                        if ( == null || dep.version == null || == null || == "unspecified")
                            return // ignore invalid dependencies
                        final dependencyNode = dependenciesNode.appendNode('dependency')
                        dependencyNode.appendNode('version', dep.version)
                        dependencyNode.appendNode('scope', scope)
                        if (!dep.transitive) {
                            // If this dependency is transitive, we should force exclude all its dependencies them from the POM
                            final exclusionNode = dependencyNode.appendNode('exclusions').appendNode('exclusion')
                            exclusionNode.appendNode('groupId', '*')
                            exclusionNode.appendNode('artifactId', '*')
                        } else if (! {
                            // Otherwise add specified exclude rules
                            final exclusionNode = dependencyNode.appendNode('exclusions').appendNode('exclusion')
                   { ExcludeRule rule ->
                                exclusionNode.appendNode('groupId', ?: '*')
                                exclusionNode.appendNode('artifactId', rule.module ?: '*')
                    // List all "compile" dependencies (for old Gradle)
                    configurations.compile.getDependencies().each { dep -> addDependency(dep, "compile") }
                    // List all "api" dependencies (for new Gradle) as "compile" dependencies
                    configurations.api.getDependencies().each { dep -> addDependency(dep, "compile") }
                    // List all "implementation" dependencies (for new Gradle) as "runtime" dependencies
                    configurations.implementation.getDependencies().each { dep -> addDependency(dep, "runtime") }
    task androidJavadocs(type: Javadoc) {
        source =
        classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
        android.libraryVariants.all { variant ->
            if ( == 'release') {
                owner.classpath += variant.javaCompile.classpath
        exclude '**/R.html', '**/R.*.html', '**/index.html'
    task androidJavadocsJar(type: Jar, dependsOn: androidJavadocs) {
        classifier = 'javadoc'
        from androidJavadocs.destinationDir
    task androidSourcesJar(type: Jar) {
        classifier = 'sources'
  4. 3. Replace, custom-artifact, 0.1-SNAPSHOT with an appropriate data
  5. 4. Use gradle clean publish command to upload artifacts.

Get more info: stackoverflow question