【问题标题】:azure devops - gradle authenticationazure devops - gradle 身份验证
【发布时间】:2020-02-12 14:18:44
【问题描述】:

我正在尝试使用 azure devops 工件存储库配置 build.gradle。它之前使用 AZURE_ARTIFACTS 凭据工作,但 azure 最近改变了 build.gradle 连接到工件存储库的方式

    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:

【问题讨论】:

    标签: gradle azure-devops build.gradle azure-artifacts


    【解决方案1】:

    我在多项目构建中遇到了类似的问题,我可以通过此文档页面上有关子项目和插件的提示来解决该问题: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'
    
        ...
    
    }
    

    【讨论】:

      【解决方案2】:

      如果它曾经有效但最近失败,您可能需要检查 PAT 是否仍然有效。尝试创建一个新的 PAT 并在settings.xml 文件中使用它来检查。

      请确保您使用最新的设置方式来配置身份验证:

      1.将此部分添加到 repositories 和 publishing.repositories 容器中的 build.gradle 文件中:

      maven {
          url 'https://pkgs.dev.azure.com/xxx/xxx/_packaging/xxx/maven/v1'
          name 'xxx'
          authentication {
              basic(BasicAuthentication)
          }
      }
      

      2.在${user.home}/.m2中添加或编辑settings.xml文件:

      <server>
        <id>looi</id>
        <username>xxx</username>
        <password>[PERSONAL_ACCESS_TOKEN]</password>
      </server>
      

      【讨论】:

      • 做了所有这些,但仍然收到错误。我可以发布,但无法从其他应用下载
      • @Lance Li-MSFT settings.xml 文件位于何处。我似乎找不到它。
      【解决方案3】:

      我有同样的问题。我通过添加 Maven 设置插件解决了它:

      buildscript {
      ...
        dependencies {
          ...
          classpath "net.linguica.gradle:maven-settings-plugin:0.5"
        }
      }
      apply plugin: 'net.linguica.maven-settings'
      

      在 gradle 成功授权 azure feed 之后。

      【讨论】:

      • 这也是我的问题。凭据是在.m2/settings.xml 中设置的,但是如果没有上述插件,gradle 就无法访问凭据。如果使用插件块的替代方法:plugins{ id 'net.linguica.maven-settings' version "0.5" }
      【解决方案4】:

      为了让插件等正确,这对我有用:

      azure-pipelines添加token环境变量:

        - task: Gradle@2
          env:
            SYSTEM_ACCESSTOKEN: $(System.AccessToken)
      

      build.gradlesettings.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)
                  }
              }
          }
      

      一些参考资料:

      How to log into Azure DevOps Artifact feed without token

      https://medium.com/developer-space/using-external-and-authentication-required-maven-repository-with-gradle-7e2e7c5b795d

      https://docs.microsoft.com/en-us/azure/devops/pipelines/build/variables?view=azure-devops&tabs=yaml#systemaccesstoken

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2022-10-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-02-02
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多