Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reference public GitHub packages from maven project

I have a GitHub repo with a library published to its own GitHub packages maven repository. And I also have another project where I want to reference this library as a dependency.

When I add the following configuration to the POM file of my project it just doesn't work.

<repositories>
 <repository>
  <id>github</id>
  <name>GitHub Packages</name>
  <url>https://maven.pkg.github.com/test-account/test-lib</url>
 </repository>
</repositories>

It requires me to authenticate. I understand that this is pretty logical as it is basically not a sources repo but an underlying maven repo. But is there a way to have normal maven access to this dependency? My library is in the public repo.

P.S. Please, do not suggest using Jitpack as I would like to have clean solution without any additional resources.

like image 555
Alexey Anufriev Avatar asked Jun 10 '26 00:06

Alexey Anufriev


1 Answers

The answer seems to be "you can't". See this comment from a GitHub staff member:

Our Maven service doesn’t allow for unauthorized access right now. We plan to offer this in the future but need to improve the service a bit before that.

For now the simplest option seems to be to create a personal access token with read access and include it in the URL of the <repository> section in your pom.xml, like this:

<repository>
  <id>github</id>
  <name>GitHub Packages</name>
  <url>https://my-user:[email protected]/my-user/my-repo</url>
</repository>

Otherwise, options are probably:

  • Create a personal access token with read access and just share it with the whole world.
  • Use the workaround described here
  • Publish to Maven Central (but that's a whole world of pain)
like image 198
Frans Avatar answered Jun 11 '26 23:06

Frans



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!