如何从 Maven 项目中引用公共 GitHub 包 [英] How to reference public GitHub packages from maven project

查看:130
本文介绍了如何从 Maven 项目中引用公共 GitHub 包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 GitHub 存储库,其中包含一个发布到其自己的 GitHub 包 maven 存储库的库.而且我还有另一个项目,我想在其中引用这个库作为依赖项.

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.

当我将以下配置添加到项目的 POM 文件时,它不起作用.

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>

它需要我进行身份验证.我知道这是非常合乎逻辑的,因为它基本上不是源代码库,而是基础的 Maven 代码库.但是有没有办法让 maven 正常访问这个依赖项?我的图书馆在公共仓库中.

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.

附言请不要建议使用 Jitpack,因为我希望在没有任何额外资源的情况下拥有干净的解决方案.

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

推荐答案

答案似乎是你不能".见 这个来自 GitHub 工作人员的评论:

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

我们的 Maven 服务目前不允许未经授权的访问.我们计划在未来提供此服务,但需要在此之前稍微改进一下服务.

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.

目前最简单的选择似乎是创建一个具有读取访问权限的个人访问令牌,并将其包含在您的 pom.xml 部分的 URL 中代码>,像这样:

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:b96e7de7514e45c5@maven.pkg.github.com/my-user/my-repo</url>
</repository>

否则,选项可能是:

  • 创建具有读取权限的个人访问令牌,然后与全世界共享.
  • 使用解决方法 此处描述
  • 发布到 Maven Central(但这是一个痛苦的世界)

这篇关于如何从 Maven 项目中引用公共 GitHub 包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆