ARTIFACTORY: How to authenticate the groovy grab resolver to resolve the dependencies via Artifactory

ARTIFACTORY: How to authenticate the groovy grab resolver to resolve the dependencies via Artifactory

AuthorFullName__c
Ujwal Poovaiah
articleNumber
000006081
FirstPublishedDate
2024-04-24T08:31:45Z
lastModifiedDate
2025-07-22
VersionNumber
2

The Groovy Grape (or Grab) resolver is a dependency management system in Groovy, similar to Maven or Gradle.  It permits you to define dependencies in your Groovy scripts, facilitating automatic downloading and integration into your project. 

To resolve dependencies via Artifactory, you can employ Ivy, necessitating parameter adjustments by updating ~/.groovy/grapeConfig.xml with login credentials. Utilizing the settings file with the properties outlined below enables the resolution of dependencies from Artifactory.

Please find the below sample script and the grapeconfig.xml file.

$   test.groovy

@GrabResolver(name='grails', root='http://artifactory.com/artifactory/maven-virtual')
@Grab(group='com.fasterxml.jackson.datatype', module='jackson-datatype-jsr310', version='2.13.2')
class Main {
    static void main(String[] args) {
        println "Testing @GrabResolver"
        println "Groovy version: ${GroovySystem.getVersion()}"
    }
}

~/.groovy/grapeConfig.xml
<ivy-settings>
  <settings defaultResolver="downloadGrapes" />
  <credentials host="artifactory.com" realm="Artifactory Realm" username="<username>" passwd="<password>" />
  <resolvers>
    <chain name="downloadGrapes">
      <ibiblio name="main" m2compatible="true" root="http://artifactory.com/artifactory/maven-virtual" />
    </chain>
  </resolvers>
</ivy-settings>

Run the script.
groovy test.groovy
Testing @GrabResolver
Groovy version: 4.0.20

Sample logs from the Artifactory.
 

==> artifactory-request.log ⇐
2024-03-29T12:19:30.278Z|562c624f5ff3b9d8|127.0.0.1|user1|HEAD|/maven-

virtual/com/fasterxml/jackson/datatype/jackson-datatype-jsr310/2.13.2/jackson-

datatype-jsr310-2.13.2.pom|200|-1|4906|113|Apache Ivy/2.5.2


2024-03-29T12:19:30.670Z|30ca56d1a4bae240|52.21127.0.0.1|user1|GET|/maven-

virtual/com/fasterxml/jackson/datatype/jackson-datatype-jsr310/2.13.2/jackson-

datatype-jsr310-2.13.2.pom|200|-1|4906|7|Apache Ivy/2.5.2
==> artifactory-service.log ⇐
2024-03-29T12:19:32.906Z [jfrt ] [INFO ] [1cdfbc5692c9e394] [o.a.r.HttpRepo:461            

] [http-nio-8081-exec-9] - maven-remote downloading 

https://repo1.maven.org/maven2/com/fasterxml/jackson/module/jackson-modules-

java8/2.13.2/jackson-modules-java8-2.13.2.pom 3.14 KB


2024-03-29T12:19:47.604Z [jfrt ] [INFO ] [60cf1a56c54ea971] [o.a.r.HttpRepo:461            

] [http-nio-8081-exec-1] - maven-remote downloading 

https://repo1.maven.org/maven2/com/fasterxml/jackson/datatype/jackson-datatype-

jsr310/2.13.2/jackson-datatype-jsr310-2.13.2-sources.jar 80.48 KB