azure devops - gradle 身份验证
azure devops - gradle authentication
我正在尝试使用 azure devops 工件存储库配置 build.gradle。它早些时候使用 AZURE_ARTIFACTS 凭证工作,但 azure 最近改变了 build.gradle 连接到工件 repo
的方式
url 'https://pkgs.dev.azure.com/dp-name/_packaging/dp-name/maven/v1'
name 'dp-name'
authentication {
basic(BasicAuthentication)
}
}
gradle 构建失败并出现以下错误
> Could not resolve all dependencies for configuration ':compileClasspath'.
> You cannot configure authentication schemes for this repository type if no credentials are provided.
* Try:
如果它曾经有效但最近失败了,您可能需要检查 PAT 是否仍然有效。尝试创建一个新的 PAT 并在 settings.xml
文件中使用它来检查。
并且请确保您使用最新的设置方式来配置身份验证:
1.Add 将此部分添加到存储库和 publishing.repositories 容器中的 build.gradle 文件:
maven {
url 'https://pkgs.dev.azure.com/xxx/xxx/_packaging/xxx/maven/v1'
name 'xxx'
authentication {
basic(BasicAuthentication)
}
}
2.Add 或编辑 ${user.home}/.m2 中的 settings.xml 文件:
<server>
<id>looi</id>
<username>xxx</username>
<password>[PERSONAL_ACCESS_TOKEN]</password>
</server>
我遇到了同样的问题。我通过添加 maven 设置插件解决了它:
buildscript {
...
dependencies {
...
classpath "net.linguica.gradle:maven-settings-plugin:0.5"
}
}
apply plugin: 'net.linguica.maven-settings'
之后 gradle 成功获得 Azure Feed 授权。
我在多项目构建中遇到了类似的问题,我能够通过此子项目和插件文档页面上的提示解决该问题:https://docs.gradle.org/current/userguide/plugins.html#sec:subprojects_plugins_dsl
这是我的根 build.gradle 文件的样子 - 注意:我不必编辑子项目 build.gradle 文件。
plugins {
id "net.linguica.maven-settings" version "0.5"
}
...
repositories {
maven {
url 'https://pkgs.dev.azure.com/<org>/<repoId>/_packaging/platform/maven/v1'
name '<name>'
authentication {
basic(BasicAuthentication)
}
}
}
...
subprojects {
apply plugin: 'net.linguica.maven-settings'
...
}
为了使插件等正确。这对我有用:
在azure-pipelines
添加token环境变量:
- task: Gradle@2
env:
SYSTEM_ACCESSTOKEN: $(System.AccessToken)
在 build.gradle
或 settings.gradle
中配置适当的存储库,如下所示:
repositories {
maven {
url = 'https://pkgs.dev.azure.com/<your project>/amplify/_packaging/<your feed>/maven/v1'
name = '<your feed>'
credentials {
username "AzureDevOps"
password "$System.env.SYSTEM_ACCESSTOKEN"
}
authentication {
basic(BasicAuthentication)
}
}
}
部分参考资料:
我正在尝试使用 azure devops 工件存储库配置 build.gradle。它早些时候使用 AZURE_ARTIFACTS 凭证工作,但 azure 最近改变了 build.gradle 连接到工件 repo
的方式 url 'https://pkgs.dev.azure.com/dp-name/_packaging/dp-name/maven/v1'
name 'dp-name'
authentication {
basic(BasicAuthentication)
}
}
gradle 构建失败并出现以下错误
> Could not resolve all dependencies for configuration ':compileClasspath'.
> You cannot configure authentication schemes for this repository type if no credentials are provided.
* Try:
如果它曾经有效但最近失败了,您可能需要检查 PAT 是否仍然有效。尝试创建一个新的 PAT 并在 settings.xml
文件中使用它来检查。
并且请确保您使用最新的设置方式来配置身份验证:
1.Add 将此部分添加到存储库和 publishing.repositories 容器中的 build.gradle 文件:
maven {
url 'https://pkgs.dev.azure.com/xxx/xxx/_packaging/xxx/maven/v1'
name 'xxx'
authentication {
basic(BasicAuthentication)
}
}
2.Add 或编辑 ${user.home}/.m2 中的 settings.xml 文件:
<server>
<id>looi</id>
<username>xxx</username>
<password>[PERSONAL_ACCESS_TOKEN]</password>
</server>
我遇到了同样的问题。我通过添加 maven 设置插件解决了它:
buildscript {
...
dependencies {
...
classpath "net.linguica.gradle:maven-settings-plugin:0.5"
}
}
apply plugin: 'net.linguica.maven-settings'
之后 gradle 成功获得 Azure Feed 授权。
我在多项目构建中遇到了类似的问题,我能够通过此子项目和插件文档页面上的提示解决该问题:https://docs.gradle.org/current/userguide/plugins.html#sec:subprojects_plugins_dsl
这是我的根 build.gradle 文件的样子 - 注意:我不必编辑子项目 build.gradle 文件。
plugins {
id "net.linguica.maven-settings" version "0.5"
}
...
repositories {
maven {
url 'https://pkgs.dev.azure.com/<org>/<repoId>/_packaging/platform/maven/v1'
name '<name>'
authentication {
basic(BasicAuthentication)
}
}
}
...
subprojects {
apply plugin: 'net.linguica.maven-settings'
...
}
为了使插件等正确。这对我有用:
在azure-pipelines
添加token环境变量:
- task: Gradle@2
env:
SYSTEM_ACCESSTOKEN: $(System.AccessToken)
在 build.gradle
或 settings.gradle
中配置适当的存储库,如下所示:
repositories {
maven {
url = 'https://pkgs.dev.azure.com/<your project>/amplify/_packaging/<your feed>/maven/v1'
name = '<your feed>'
credentials {
username "AzureDevOps"
password "$System.env.SYSTEM_ACCESSTOKEN"
}
authentication {
basic(BasicAuthentication)
}
}
}
部分参考资料: