How to use the repo credentials from settings.xml for accessing artifacts from maven repositories in Artifactory

The script is using the following plugins

plugins {
 id 'com.jfrog.artifactory' version '3.0.1'
 id 'maven'
 id 'java'
}

If the code specifies the username and password then the dependencies are resolved and returned from Artifactory. If the script does not specify the credentials, then the following is returned:

---- > > Could not resolve org.apache.commons:commons-lang3:3.3.2. >

Required by: >

com.ooooo.impact.common:Encryption Maven project:1.0-SNAPSHOT >

Could not HEAD ‘http://repo1.xxx.com/artifactory/libs-snapshots/org/apache/commons/commons-lang3/3.3.2/commons-lang3-3.3.2.pom’. Received status code 401 from server: Unauthorized >

Could not HEAD ‘http://repo1.xxx.com/artifactory/libs-releases/org/apache/commons/commons-lang3/3.3.2/commons-lang3-3.3.2.pom’. Received status code 401 from server: Unauthorized ----

Is there a way to read the credentials from the .m2/settings.xml file and use the credentials for dependencies?

Gradle doesn’t provide any built-in support for reading Maven settings files. You may want to take a look at this plugin however it doesn’t integrate with the artifactory plugin. However, if you are simply using Artifactory as a Maven repo, you likely don’t need to use the plugin anyway.

Thanks for the suggestion. I updated the build gradle script to:

plugins {
 id "net.linguica.maven-settings" version "0.3"
 id 'maven'
 id 'java'
}

If the settings.xml file is located in the user location ${user.home}/.m2 then the build was successful! thanks Also, if the settings.xml file is in the $M2_HOME/conf then the build was also successful.

I have some questions:

  1. I have been testing with the --refresh-dependencies option to avoid cached values. Are there other options or test procedures? 2. Does the maven-settings totally replace the artifactory plugin? When would the artifactory plugin be needed? 3. The gradle build script requires that entries for the repositories with the name and url values. Is this true? Is there a way to not have the repository information in the build script?
repositories {
 maven {
  name "O-Snaps"
  url "http://repo1.u.com/artif/libs-snaps"
 }
...
}

I confirm that the maven-settings plugin allows the build to access and resolve for dependencies, but does not integrate with the artifactory plugin for the repository credentials.

Could you elaborate on how to access Artifactory as a Maven repo for deploying artifacts? Thanks!

We are using the maven-publish plugin to push artifacts into Artifactory. https://gradle.org/docs/current/userguide/publishing_maven.html

Gradle also has the older maven plugin. https://gradle.org/docs/current/userguide/maven_plugin.html

  1. Why would you not want to use cached artifacts? Are you using a lot of snapshot dependencies? If so, we can configure caching on those separately.

  2. The Artifactory plugin just provides some nice integration with Artifactory repositories, however, it is not strictly required. You can still simply configure your Artifactory repo as a regular Maven repo in Gradle.

  3. The other option would be to use the maven-settings plugin mirror functionality. You could then configure your Artifactory repo as a mirror in your settings.xml and then just add something like ‘mavenCentral()’ to your build script which would be replaced by your local repository.