javamavengradlegithub-package-registry

How to push to Github package registry with Gradle


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


Solution

  • 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.