Configuring HTTP Basic Auth secured repository is a little bit hard. Just remember the following things:

  • For simplicity we use the same login value for everyone - myMavenRepo.
  • There is difference between repository credentials and service credentials. Don't mess them up.

Help / Configuring Gradle build file for HTTP Basic Auth secured repository

Security

Direct usage of password in build.gradle file to your repository is not good a idea. Instead we suggest you to store this information in ~/.gradle/gradle.properties file:

myMavenRepoReadPassword=${yourHttpAuthReadPassword}
myMavenRepoWritePassword=${yourHttpAuthWritePassword}

Replace ${yourHttpAuthReadPassword}, ${yourHttpAuthWritePassword} with password to your read/write repository.

Get more info: official documentation, stackoverflow question

Reading

To read data from your repository you should use read URL and password to your read repository. Let's add them to /path/to/project/build.gradle file:

repositories {
    maven {
        url '${myMavenRepoReadUrl}'
        credentials {
            username 'myMavenRepo'
            password myMavenRepoReadPassword
        }
    }
}

Replace ${myMavenRepoReadUrl} with read URL to your repository.

Publishing artifacts

To publish data to repository you should use write URL and password to your write repository. Let's add them to /path/to/project/build.gradle file:

apply plugin: 'maven-publish'

group = 'com.my-project'
version = '0.1-SNAPSHOT'

publishing {
    repositories {
        maven {
            url '${myMavenRepoWriteUrl}'
            credentials {
                username 'myMavenRepo'
                password myMavenRepoWritePassword
            }
        }
    }

    publications {
        maven(MavenPublication) {
            from components.java
        }
    }
}

Replace ${myMavenRepoWriteUrl} with write URL to your repository and com.my-project, 0.1-SNAPSHOT with an appropriate data.

To upload artifacts use gradle publish command.

You can also use maven plugin to upload your data

Get more info: maven-publish plugin doc, maven plugin doc, blog post