Search code examples
gradleazure-devopsbuild.gradleazure-artifacts

azure devops - gradle authentication


I am trying to configure build.gradle with azure devops artifacts repo. It was working earlier with AZURE_ARTIFACTS credentials BUT azure recently changed the way build.gradle connects to artifacts repo

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

gradle build fails with the following error

> Could not resolve all dependencies for configuration ':compileClasspath'.
   > You cannot configure authentication schemes for this repository type if no credentials are provided.

* Try:


Solution

  • If it once worked but recently fails, you may need to check if the PAT is still valid. Try creating a new PAT and use it in settings.xml file to check.

    enter image description here

    And please make sure you use the latest setup way to configure the authentication:

    1.Add this section to your build.gradle file in both the repositories and publishing.repositories containers:

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

    2.Add or edit the settings.xml file in ${user.home}/.m2:

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