Sign up ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I want to do something like this in a chef recipe:

maven_artifact "/opt/foo/my.jar" do
  source ""

But I can't find a cookbook which provides this. I've written something which basically does this but it doesn't handle snapshots, which requires parsing maven-metadata.xml. Before I plunge into this, I wanted to be sure I wasn't missing something obvious since this seems like a basic usecase.

share|improve this question
You can simply use maven cookbook – Cherry Dec 10 '14 at 7:39

3 Answers 3

up vote 4 down vote accepted

Based on Apache Buildr code :

You can do something like this:

def snapshot?
  version =~ /-SNAPSHOT$/

if snapshot?
    metadata_path = "#{group_path}/#{id}/#{version}/maven-metadata.xml"
    metadata_xml = repo_url + metadata_path, metadata_xml
    metadata =
    timestamp = REXML::XPath.first(metadata, '//timestamp')
    build_number = REXML::XPath.first(metadata, '//buildNumber')
    snapshot_of = version[0, version.size - 9]
    classifier_snippet = (classifier != nil) ? "-#{classifier}" : ""
    repo_url + "#{group_path}/#{id}/#{version}/#{id}-#{snapshot_of}-#{timestamp.text}-#{build_number.text}#{classifier_snippet}.#{type}"
share|improve this answer

If you use Artifactory as your Maven repository, a more elegant solution is at hand.

Starting from version 2.6.0 a request for a non-unique artifact can return the latest available snapshot.

To utilize this feature, first make sure that the target repository is defined with a unique snapshot policy, then request the desired artifact using a non-unique snapshot version such as:


And the latest unique snapshot of artifact with a base revision of 1.0 will be returned.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.