1

I am currently using gradle publish to be able to ublish the jar into Azure Artifact. I have followed the instructions as:

`maven {
url 'https://azuredevops.url/organization-name/project-name/_packaging/artifact/maven/v1'
name 'name'
authentication {
    basic(BasicAuthentication)
}}`

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

    `<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
                              https://maven.apache.org/xsd/settings-1.0.0.xsd">
  <servers>
    <server>
      <id>id</id>
      <username>username</username>
      <password>[PERSONAL_ACCESS_TOKEN]</password>
    </server>
  </servers>
</settings>`

and after using gradle publish, I received:

  • What went wrong: Execution failed for task ':publishMavenJavaPublicationToartifactnameRepository'.

Failed to publish publication 'mavenJava' to repository 'artifact name' Could not GET 'https://azuredevops.url/organization-name/project-name/_packaging/artifact/maven/v1/com/name/apps/utils/name/1.0.0-SNAPSHOT/maven-metadata.xml'. Received status code 403 from server: Forbidden

PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target [org.gradle.internal.buildevents.BuildExceptionReporter]

After clicking on the link I get following:

{"$id":"1","innerException":null,"message":"File name 'maven-metadata.xml'.' does not start 
     with artifactId 'artifact-name'","typeName":"Microsoft.VisualStudio.Services.Maven.WebApi.Exceptions.MavenInvalidFilenameException, Microsoft.VisualStudio.Services.Maven.WebApi","typeKey":"MavenInvalidFilenameException","errorCode":0,"eventId":3000}

Can someone help here ?

  • Did you replace the Personal Access Token in this line `[PERSONAL_ACCESS_TOKEN]` with one you generated? The token needs read and write scopes. So your settings.xml should look something like `lkjfds7987dsfhkdfhf87hkjkj` – James Reed Jul 25 '22 at 15:21
  • Yes, I did changed that to the PAT which has full access. – Priyanka Sharma Jul 26 '22 at 14:48
  • you also need to have some gradle plugin to get the user/pw from settings.xml. Azure devops suggests `net.linguica.maven-settings:0.5` in it's "get the tools" seciton when you click on "connect to feed". Normally, gradle does not take any settings from maven settings.xml. but this plugin does the trick. – markus Jul 27 '22 at 13:51
  • As checked, the plugin net.linguica.maven-settings:0.5 is already there in build.gradle – Priyanka Sharma Jul 28 '22 at 07:04

2 Answers2

0

As a first step you could try to add the authentication directly into the Gradle file and if everything works then use the Maven settings file:

publishing {
    publications {
        mavenJava(MavenPublication) {
            from components.java
        }
    }

    repositories {
        maven {
            credentials {
                username "token name"
                password "password"
            }
            URL 'feed URL
            name 'feed name'
            authentication {
                basic(BasicAuthentication)
            }
        }
    }
}

It is important to note that the username is the token name of the personal access token of azure. Also to use the maven settings file, it is mentioned that another plugin is required:

Get the tools in azure

However, one could store credentials also in a ~/.gradle/gradle.properties file, as this file is generally not committed.

Stefan
  • 1,151
  • 1
  • 8
  • 13
0

Firstly for PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target [org.gradle.internal.buildevents.BuildExceptionReporter]

Keytool import certificate command

1. keytool -import -trustcacerts -alias mdecert -file Certificate.cer -keystore /usr/lib/jvm/jre-1.8.0/lib/security/cacerts -storepass changeit

2. keytool -list -keystore "/usr/lib/jvm/jre-1.8.0/lib/security/cacerts"

Then 403 was faced, for that

The issue resolved once the proxy settings were changed as in case of gradle publish the traffic was coming towards the Azure Artifacts and proxy was not required there. Hence I added nonproxyhosts alongwith the URL in gradle.properties file which resolved the issue.