如何对Gradle的Github软件包使用令牌身份验证? [英] How do I use token auth for Github Packages from Gradle?

查看:74
本文介绍了如何对Gradle的Github软件包使用令牌身份验证?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

https://docs.github.com/zh-cn/packages/guides/configuring-gradle-for-use-with-github-packages 似乎不起作用,因为看起来GitHub软件包实际上并未接受基本认证我有从 https://github.com/settings/tokens 中检索到的来自GitHub的令牌,但我没有在Gradle中看不到将其用于Bearer身份验证的方法.

The example configuration on https://docs.github.com/en/packages/guides/configuring-gradle-for-use-with-github-packages doesn't seem to work, as it looks like GitHub packages doesn't actually accept Basic auth. I have the token from GitHub retrieved from https://github.com/settings/tokens but I don't see a way to use it for Bearer auth in Gradle.

我要回答这个问题.

推荐答案

gradle.build.kts 的存储库部分中,包括以下内容:

In the repository section of your gradle.build.kts, include the following:

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> 替换为拥有存储库的用户或组织的名称,将< GIT_REPO> 替换为生成信息库的git存储库的名称.包裹.然后,您将在 https://github.com/settings/tokens 上生成的令牌添加到 gradle.properties build.gradle.kts 在同一目录中.看起来应该像这样:

Replacing <OWNER> with the name of the user or organization that owns the repo and and <GIT_REPO> with the name of the git repository that generates the package. You then add the token you generated on https://github.com/settings/tokens to gradle.properties in the same directory as your build.gradle.kts. It should look like:

gpr.token=<Token, without quotes>

该文件可能已经存在其他设置,您无需删除它们.请勿提交此文件.

The file may already exist with other settings, you don't need to remove them. DO NOT COMMIT THIS FILE.

如果这仍然不起作用,请验证您生成的令牌是否具有 read:packages 权限.如果没有,则需要生成一个新令牌.

If this still does not work, verify that the token you generated has the read:packages permission. If it doesn't, you'll need to generate a new token.

希望这可以节省您4个小时的时间,而我花了我的时间才弄清楚发生了什么事情.

Hopefully this saves you the 4 hours it took me to figure out what was happening.

这篇关于如何对Gradle的Github软件包使用令牌身份验证?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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