Skip to content

Instantly share code, notes, and snippets.

@twaddington
Last active July 18, 2022 21:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save twaddington/91711a0c96ce7d0324caf8b94dda8dd8 to your computer and use it in GitHub Desktop.
Save twaddington/91711a0c96ce7d0324caf8b94dda8dd8 to your computer and use it in GitHub Desktop.
Publishing a package from a file to a private GitHub Maven repository

Publishing a package from a file to a private GitHub Maven repository

Add your credentials to ~/.m2/settings.xml

Where token is your personal access token.

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
                      http://maven.apache.org/xsd/settings-1.0.0.xsd">
  <servers>
    <server>
      <id>github</id>
      <username>GITHUB_USERNAME</username>
      <password>GITHUB_TOKEN</password>
    </server>
  </servers>
</settings>

Publish your existing package using the mvn command-line tool

$ mvn deploy:deploy-file \
      -Dfile=/path/to/file.aar \
      -DpomFile=/path/to/file.pom \
      -DrepositoryId=github \
      -Durl=https://maven.pkg.github.com/OWNER/REPO

(optional) In your Gradle project

Add your maven credentials to your project like you would for any other password protected package registry.

allprojects {
  repositories {
    maven {
        url 'https://maven.pkg.github.com/OWNER/REPO'
        credentials {
            username = project.findProperty("mvn.github.user") ?: System.getenv("USERNAME")
            password = project.findProperty("mvn.github.token") ?: System.getenv("TOKEN")
        }
    }
  }
}

Note: The Gradle Maven plugin doesn't read from settings.xml so configuring a profile with a repository in ~/.m2/settings.xml won't do any good: gradle/gradle#1236

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment