maven - 如何使用来自 Gradle 的 Github 包的令牌身份验证?
问题描述
https://docs.github.com/en/packages/guides/configuring-gradle-for-use-with-github-packages上的示例配置似乎不起作用,因为看起来 GitHub 包实际上并没有接受基本身份验证。我从https://github.com/settings/tokens检索了来自 GitHub 的令牌,但我没有看到将其用于 Gradle 中的 Bearer auth 的方法。
我问这个是为了回答它。
解决方案
在您的存储库部分中gradle.build.kts
,包括以下内容:
repositories {
...
maven("https://maven.pkg.github.com/<OWNER>/<GIT_REPO>") {
credentials(HttpHeaderCredentials::class) {
name = "Authorization"
value = "Bearer ${project.findProperty("gpr.token") as String}"
}
authentication {
create<HttpHeaderAuthentication>("header")
}
}
}
替换<OWNER>
为拥有 repo 的用户或组织<GIT_REPO>
的名称以及生成包的 git 存储库的名称。然后,将在https://github.com/settings/tokens上生成的令牌添加到gradle.properties
与build.gradle.kts
. 它应该看起来像:
gpr.token=<Token, without quotes>
该文件可能已经存在其他设置,您无需删除它们。不要提交此文件。
如果这仍然不起作用,请验证您生成的令牌是否具有read:packages
权限。如果没有,您将需要生成一个新令牌。
希望这可以为您节省 4 个小时的时间来弄清楚发生了什么。
推荐阅读
- python - python根据列数据生成数据
- neo4j - Neo4j Cypher 如何计算关系属性的百分比
- react-native - 如何添加
在通过数据库获取数据的 FlatList 之前 - javascript - 无法访问 IOS Safari 上的对象,但适用于桌面 Chrome
- reactjs - React 自定义 Hook 以返回一个对象
- python - 在 Python 中将对象的 ndarray 保存到文件
- ansible - 如何在运行 ansible 的服务器上创建目录
- google-maps - 谷歌地图 api 方向服务(多路线和 30 个航点)
- function - 我可以将 onEdit 函数限制为 Google 表格中的复选框单元格吗?
- tensorflow - 本地预测的 gcloud 问题