Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Copilot Lvl 2
Message 1 of 4

GitHub package registry as Maven repo with many private libraries

I want to use the GitHub package registry as a Maven repository for a multi-git-repo private project. Say I have app1, app2, lib1, lib2, both apps require both apps each.

 

Currently, I have to declare a maven repositoy for each of the libs I'm using in the apps, e.g. like this:

 

build.gradle:

repositories {
    mavenCentral()
    maven {
        name = "GitHubPackages-lib1"
        url = "https://maven.pkg.github.com/OWNER/lib1"
        credentials {
            username = System.getenv("GITHUB_USERNAME")
            password = System.getenv("GITHUB_TOKEN")
        }
    }
    maven {
        name = "GitHubPackages-lib2"
        url = "https://maven.pkg.github.com/OWNER/lib2"
        credentials {
            username = System.getenv("GITHUB_USERNAME")
            password = System.getenv("GITHUB_TOKEN")
        }
    }
}

 

One can easily see that this will not scale well. 

 

With NPM packages, I get a much better developer experience. There, I can provide something like 

 

@OWNER:registry=https://npm.pkg.github.com

in my application's .npmrc and will have access to all published NPM packages in all repositories of OWNER, where that user token has access to. Very convenient!

 

It would be really nice to have something similar for Maven packages as well.

 

I have read that I can publish multiple packages to one github repository, so maybe I could setup my own OWNER/mavenrepo and publish all libraries into that. But then the published packages would not be visible on the packages tab of the library, right?

3 Replies
Highlighted
Copilot Lvl 3
Message 2 of 4

Re: GitHub package registry as Maven repo with many private libraries

I definitely support the idea of having one central maven repository for all projects. Would really be great.

 

Publishing to one repository from different other repositories (projects) didn't work for me. I received a HTTP error 422 trying to do so.

Highlighted
Ground Controller Lvl 1
Message 3 of 4

Re: GitHub package registry as Maven repo with many private libraries

Hi,

 

You should be able to publish to another repository. 

However it has be in a different package name.

Package names have to be unique across repositories in an organization

You need another token to publish GITHUB_TOKEN will not work. So I had to set up another secret

Highlighted
Copilot Lvl 2
Message 4 of 4

Re: GitHub package registry as Maven repo with many private libraries

I just came across this behavior, and I must agree that it is pretty awful. Maven has the `scm` tag (see docs here), so that could be used by Github in the same way the `publishConfig` is used in the land of npm. This can also be done via gradle.

 

Even without introspecting on the scm tag, Java packages are inherently namespaced (unlike Node packages), so publishing at least at an org / user level should be easily doable without worrying about namespace conflicts.

 

The current implementation is a pretty poor one for anyone using Java.