How to push to Github package registry with Gradle

gradle github dependency
github package registry maven
gradle private github dependency
github package registry maven-metadata xml
how to use github packages
github packages java
github actions
github repo api key

Trying to push the Gradle project to Github package registry, but not working as expected.

Using io.freefair.github.package-registry-maven-publish plugin for Gradle.

Configure GitHub in build.gradle with data needed to publish - code below. And run the publishing task publishAllPublicationsToGutHub. Getting no error but I can't see my package in GitHub package registry.

github {
    slug
    username = "myGitUserName"
    token = "myTokenWithRightAccess"
    tag = "HEAD"
    travis = true
}

Expecting some examples of how to publish to Github package registry with Gradle or what I'm doing wrong when publishing

New answer:

GitHub has published the official guide: Configuring Gradle for use with GitHub Packages.


Old answer:

It seems like the plugin is not very stable yet. Take a look at the repository I've created that has everything set up. I managed to publish a few packages with that plugin here.

Even the packages are published, Gradle shows task as failed, due to some issues with maven-metadata.xml:

> Task :publishMainPublicationToGitHub madhead Maven PackagesRepository FAILED
Could not transfer metadata so57323260:test/maven-metadata.xml from/to remote (https://maven.pkg.github.com/madhead): Could not get resource 'so57323260/test/maven-metadata.xml'

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':publishMainPublicationToGitHub madhead Maven PackagesRepository'.
> Failed to publish publication 'main' to repository 'GitHub madhead Maven Packages'
   > Could not GET 'https://maven.pkg.github.com/madhead/so57323260/test/maven-metadata.xml'. Received status code 422 from server: Unprocessable Entity

But that's ok, probably will be fixed one day.

I've noticed, that the packages might not be published (see the linked issue) because of the incorrect groupId of a Maven publication. It seems like right now it should be equal to the Github's project name. So, in my case, I had to use so57323260 as a groupId for a madhead/so57323260 project. That's not how packages work in Maven generally, so that might be your issue.

How to push to Github package registry with Gradle, New answer: GitHub has published the official guide: Configuring Gradle for use with GitHub Packages. Old answer: It seems like the plugin is  Configuring Gradle for use with GitHub Packages You can configure Gradle to publish packages to GitHub Packages and to use packages stored on GitHub Packages as dependencies in a Java project. GitHub Packages is available with GitHub Free, GitHub Pro, GitHub Free for organizations, GitHub Team, GitHub Enterprise Cloud, and GitHub One.

I was able to publish to the Github Package Registry using the maven-publish plugin. It seems to work just fine now.

My build.gradle file looks like this:

buildscript {
    repositories {
        mavenCentral()
    }
}

plugins {
    id 'java'
    id 'maven-publish'
}

group 'com.company.project'
archivesBaseName = 'library-name'
version '0.1.0'

repositories {
    mavenCentral()
}

dependencies {
  // java dependencies
}

publishing {
    repositories {
        maven {
            name = "Github"
            url = uri("https://maven.pkg.github.com/<OWNER>/<REPO>")
            credentials {
                username = findProperty("github.username")
                password = findProperty("github.token")
            }
        }
    }
    publications {
        register("jar", MavenPublication) {
            from(components["java"])
            pom {
                url.set("https://github.com/<OWNER>/<REPO>.git")
            }
        }
    }
}

Put your github username and token into the gradle.properties file.

How to configure Gradle, Github Package Registry Maven, How to configure Gradle, Github Package Registry Maven apply plugin: "​maven-publish" publishing { repositories { maven { name = "Github" url name: CI on: [push] jobs: build: runs-on: ubuntu-latest steps: - uses:  You can authenticate to GitHub Package Registry with Gradle using either Gradle Groovy or Kotlin DSL by editing your build.gradle file (Gradle Groovy) or build.gradle.kts file (Kotlin DSL) file to include your personal access token. You can also configure Gradle Groovy and Kotlin DSL to recognize a single package or multiple packages in a repository.

GitHub has published the official document for How to use Gradle with GitHub packager

https://help.github.com/en/github/managing-packages-with-github-packages/configuring-gradle-for-use-with-github-packages#authenticating-to-github-packages

Publishing to GitHub Packages with Gradle and GitHub Actions, In November 2019 GitHub released GitHub Packages and GitHub Actions to the general public. Packages allows library owners to publish their  GitHub Packages offers precisely that, with providing a package registry for each GitHub account, allowing each of your repositories to serve as a registry for artifacts as well.

Complete those properties correctly

  1. OWNER
  2. REPOSITORY
  3. USERNAME (or gradle property gpr.user)
  4. PASSWORD (or gradle property gpr.key)

@See demo

  1. https://github.com/youngerier/packagesdemo

  2. https://help.github.com/en/github/managing-packages-with-github-packages/configuring-gradle-for-use-with-github-packages

Use Github to deploy and self host a package, We are going to host a kotlin based project as a maven package using all the Github package registry is still in Beta, it aims to replace basically everything else With that you can build and test your project at each push. How to configure Gradle, Github Package Registry Maven. GitHub Packages. trevjonez. May 23, 2020, 5:34am #1. I was just playing with this and thought I would share

Publish Android libraries to GitHub Packages, For Maven repos, Gradle will download the dependencies using the pom file which will contain the dependencies list. In this sample code/project,  Re: How to configure Gradle, Github Package Registry Maven @MarvinSchramm They responded asking for reproduction steps which I provided and have not heard anything since then. additionally they don't handle the maven-metadata.xml correctly which results in 400 errors when gradle tries to read what is there before publishing a new snapshot.

GitLab Maven Repository, After the Packages feature is enabled, the Maven Repository will be available for all new projects by Adding the GitLab Package Registry as a Maven remote. Store your packages in the same secure environment as your source code, all protected by your GitHub credentials. Integrate packages with your workflows With a full API and webhooks support, you can extend your workflows to work with GitHub Packages.

Introducing GitHub Package Registry, And it supports familiar package management tools: JavaScript (npm), Java (​Maven), Ruby (RubyGems), .NET (NuGet), and Docker images, with  GitHub Packages is available with GitHub Free, GitHub Pro, GitHub Free for organizations, GitHub Team, GitHub Enterprise Cloud, and GitHub One. GitHub Packages is not available for private repositories owned by accounts using legacy per-repository plans.

Comments
  • Thank you mate, it works for me, have the same error as you, on "3.8.2" version it doesn't work, have a different error. Expected that I need only provide "GitHub" block to make publish but I needed to add the "publishing" block and "maven-publish" plugin to make it works.
  • Yeah. Let's stay tuned on GitHub issues.
  • @DOIT, on, SO it's a good practice to ask new questions for... new questions. So, I've asked one for you here (and replied as well!). Take a look.
  • It just looks like this feature is too beta. I was able to publish with version x.y.z. Then I was not able to publish next version. Then I was able to publish when I removed version at all. Then I'm not able to publish anymore at all :)
  • The gotcha in our case was the groupId and version in the publications.gpr block
  • You should not put you GitHub token into the gradle.properties in the repository. The token is a secret that must not be public to other uses.