How can I retrieve from an Artifactory Ivy repository a set of custom data files?


(tetractius) #1

In a project ‘tProject’ have a custom task ‘dataProducer’ that is producing some custom binary data with a custom extention (say, “.dat”) I create a custom configuration:

configurations {
 tConfiguration
}

I define a specific group and version

group
 = 'tGroup'
version = '0.6'

I configure the artifactory plug-in as:

artifactory {
 contextUrl = "http://tartifactory:8081/artifactory"
 //The base Artifactory URL if not overridden by the publisher/resolver
    publish {
  repository {
   repoKey = 'libs-release-local'
   username = project.getProperties().getAt("artifactory_user")
   password = project.getProperties().getAt("artifactory_password")
   maven = false
   ivy {
    ivyLayout = '[organization]/[module]/ivy-[revision].xml'
    mavenCompatible = false
   }
  }
      defaults {
        publishConfigs ('tConfiguration')
   publishBuildInfo = true
   publishArtifacts = true
   publishPom = false
   publishIvy = true
  }
 }
          resolve {
  ...
 }
}

And finally the output of my tasks ‘dataProducer’ are declared as:

artifacts {
  tConfiguration file: file('fTest.dat'), name: 'fTest', type: 'binary', module: "tProject"
  tConfiguration file: file('Another_fTest.dat'), name: 'Another_fTest', type: 'binary', module: "tProject"
 }

This will publish on artifactory something like: http://tartifactory:8081/artifactory/libs-release-local/tGroup/tProject/ivy-0.6.xml http://tartifactory:8081/artifactory/libs-release-local/tGroup/tProject/0.6/fTest-0.6.dat http://tartifactory:8081/artifactory/libs-release-local/tGroup/tProject/0.6/Another_fTest-0.6.dat

The contents of the generated ivy-0.6.xml is:

<?xml version="1.0" encoding="UTF-8"?>
<ivy-module version="2.0" xmlns:m="http://ant.apache.org/ivy/maven">
    <info organisation="tGroup"
        module="tProject"
        revision="0.6"
        status="integration"
        publication="20131001114019"
    />
    <configurations>
        <conf name="archives" visibility="public" description="Configuration for archive artifacts."/>
        <conf name="default" visibility="public" description="Configuration for default artifacts."/>
        <conf name="tConfiguration" visibility="public"/>
    </configurations>
    <publications>
        <artifact name="fTest" type="binary" ext="dat" conf="archives,tConfiguration"/>
        <artifact name="Another_fTest" type="binary" ext="dat" conf="archives,tConfiguration"/>
    </publications>
</ivy-module>

Then I have another very simple project that needs to fetch back those files:

artifactory {
 contextUrl = "http://tartifactory:8081/artifactory"
    publish {
  ...
  }
        resolve {
        repository {
            repoKey = 'libs-release'
            maven = false
            ivy {
                ivyLayout = '[organization]/[module]/ivy-[revision].xml'
                mavenCompatible = false
            }
        }
    }
}
  configurations {
 tConfiguration
}
    repositories {
 ivy {
                artifactPattern "http://tartifactory:8081/artifactory/libs-release/[organization]/[module]/[revision]/[artifact]-[revision].[ext]"
                ivyPattern
     "http://tartifactory:8081/artifactory/libs-release/[organisation]/[module]/ivy-[revision].xml"
 }
}
   dependencies {
 tConfiguration group:'tGroup', name: 'tProject', version:'0.6', ext: 'dat'
}
    task fetchDat(type: Copy) {
 from configurations.tConfiguration
  into "$buildDir"
}

But I get the following error:

$ gradle fetchDat -q
  FAILURE: Build failed with an exception.
  * What went wrong:
Could not resolve all dependencies for configuration ':tConfiguration'.
> Could not download artifact 'tGroup:tProject:0.6@dat'
   > Artifact 'tGroup:tProject:0.6@dat' not found.
  * Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

When I run in --debug mode, I see that it is trying to download:

http://tartifactory:8081/artifactory/libs-release-local/tGroup/tProject/ivy-0.6.xml
http://tartifactory:8081/artifactory/libs-release-local/tGroup/tProject/0.6/tProject-0.6.dat

And it fails on the second one. It seems indeed that in the “artifactPattern” the ‘[artifact]’ value is the the name of the project rather than the name of the artifact (my understanding is that it should be mapped on ). If that file is present is named like that is downloaded with no issues. But the question is:

How can I download different binary files with different names from artifactory?