How to pin the version of a SNAPSHOT dependency in an Ammonite script

196 Views Asked by At

Ammonite can download dependencies from Maven repositories.

I'm using a SNAPSHOT dependency, and I'd like to use always the cached version, in order to avoid using possible untested newer versions. Is this possible?

I know that Ammonite uses lately Coursier and before Ivy, so some information I've found maybe outdated.

Some ideas I'm having is to install the current SNAPSHOT version in a local repository with another name.

3

There are 3 best solutions below

0
On BEST ANSWER

Create a local .ivy2/local repository with the following directory structure:

organization/moduleId/version/ivys
                              jars
                              poms

Create a new ivy.xml inside ivys directory like this:

<?xml version="1.0" encoding="UTF-8"?>
<ivy-module version="2.0" xmlns:e="http://ant.apache.org/ivy/extra">
    <info organisation="myorg" module="mymod" revision="someVersion" status="integration" e:scalaVersion="2.12" e:sbtVersion="0.13">
        <description>
        my module
        </description>
    </info>
    <configurations>
        <conf name="compile" visibility="public" description=""/>
        <conf name="runtime" visibility="public" description="" extends="compile"/>
        <conf name="test" visibility="public" description="" extends="runtime"/>
        <conf name="provided" visibility="public" description=""/>
        <conf name="optional" visibility="public" description=""/>
        <conf name="sources" visibility="public" description=""/>
        <conf name="docs" visibility="public" description=""/>
        <conf name="pom" visibility="public" description=""/>
    </configurations>
    <publications>
        <artifact name="sikulix2tigervnc" type="pom" ext="pom" conf="pom"/>
        <artifact name="sikulix2tigervnc" type="jar" ext="jar" conf="compile"/>
    </publications>
    <dependencies>
    </dependencies>
</ivy-module>

Place in the jars directory the *.jar with proper name and in poms the *.pom.

Problem is that Coursier won't donwload transitive dependencies, so add extra import $ivy.....

0
On

Doing this conflicts with the design of dependency management systems, and may be a bad idea, but it can be done. There are a couple of methods, depending on your situation.

If you have control of the repository, or are the person deploying the artifact, you can turn on the "unique snapshot versions" feature, which will give you exactly what you're looking for. (Take a look at http://maven.apache.org/pom.html#Repository)

If you aren't the one deploying, and don't have control of the repo, then yes I suspect copying a specific version of the artifact, possibly with a unique name, version, or classifier, might be your best option.

Caveat: All that being said, this seems like a bad idea -- the SNAPSHOT version is supposed to be the latest and greatest that passed all its tests, and shouldn't be treated like a released version that never changes. It seems like if you want a version that's not going to change, you shouldn't be using SNAPSHOT. But only you know your use case.

0
On

@jwismar, I agree that working with snapshot versions should be avoided.

But in case you have to use it, here is how I do it:

export COURSIER_TTL=inf
myscript.sc

COURSIER_TTL environment variable controls how long snapshots are held. By default, 24 hours.

In this way, the cached version will always be used.

UPDATE: But there is a bug, that prevents it to work.