Import $ivy in Ammonite

4.3k views Asked by At

I need to import sikulixapi in an Ammonite script. I could be able to do so.

So if I do from the interactive console of Ammonite this:

@ import $ivy.`com.sikulix:sikulixapi:1.1.0` 
https://repo1.maven.org/maven2/com/sikulix/sikulixapi/1.1.0/sikulixapi-1.1.0.pom
  100,0% [##########] 5,3 KiB (37,6 KiB / s)
https://repo1.maven.org/maven2/com/nativelibs4java/bridj/0.6.2/bridj-0.6.2.pom
  100,0% [##########] 18,1 KiB (226,0 KiB / s)
https://repo1.maven.org/maven2/com/sikulix/sikulixlibslux/1.1.0/sikulixlibslux-1.1.0.pom
  100,0% [##########] 2,6 KiB (20,8 KiB / s)
https://repo1.maven.org/maven2/org/swinglabs/swing-layout/1.0.3/swing-layout-1.0.3.pom
  100,0% [##########] 858 B (6,5 KiB / s)
https://repo1.maven.org/maven2/com/nativelibs4java/nativelibs4java-parent/1.8/nativelibs4j…
  100,0% [##########] 16,8 KiB (204,3 KiB / s)
Failed to resolve ivy dependencies:
  jxgrabkey:jxgrabkey:1.0 
    not found: /home/jenkins/.ivy2/local/jxgrabkey/jxgrabkey/1.0/ivys/ivy.xml
    not found: https://repo1.maven.org/maven2/jxgrabkey/jxgrabkey/1.0/jxgrabkey-1.0.pom

But jxgrabkey does exist in Maven.

This fails also:

@ import $ivy.`jxgrabkey:jxgrabkey:1.0` 
Failed to resolve ivy dependencies:abkey/jxgrabkey/1.0/jxgrabkey-1.0.pom.sha1

I'm not using any HTTP proxy.

Other versions of sikulixapi have other problems:

@ import $ivy.`com.sikulix:sikulixapi:1.1.2` 
Failed to resolve ivy dependencies:
  com.sikulix:sikulix2tigervnc:2.0.0-SNAPSHOT 
    not found: /home/jenkins/.ivy2/local/com.sikulix/sikulix2tigervnc/2.0.0-SNAPSHOT/ivys/ivy.xml
    not found: https://repo1.maven.org/maven2/com/sikulix/sikulix2tigervnc/2.0.0-SNAPSHOT/sikulix2tigervnc-2.0.0-SNAPSHOT.pom
  com.github.vidstige:jadb:-v1.0-g94ebf38-23 
    not found: /home/jenkins/.ivy2/local/com.github.vidstige/jadb/-v1.0-g94ebf38-23/ivys/ivy.xml
    not found: https://repo1.maven.org/maven2/com/github/vidstige/jadb/-v1.0-g94ebf38-23/jadb--v1.0-g94ebf38-23.pom

@ import $ivy.`com.sikulix:sikulixapi:1.1.1` 
https://repo1.maven.org/maven2/com/sikulix/sikulixapi/1.1.1/sikulixapi-1.1.1.pom
100,0% [##########] 6,6 KiB (46,5 KiB / s)
https://repo1.maven.org/maven2/com/melloware/jintellitype/1.3.9/jintellitype-1.3.9.pom
100,0% [##########] 9,9 KiB (216,3 KiB / s)
Failed to resolve ivy dependencies:
  com.github.vidstige:jadb:-v1.0-g94ebf38-23 
    not found: /home/jenkins/.ivy2/local/com.github.vidstige/jadb/-v1.0-g94ebf38-23/ivys/ivy.xml
    not found: https://repo1.maven.org/maven2/com/github/vidstige/jadb/-v1.0-g94ebf38-23/jadb--v1.0-g94ebf38-23.pom

Tried with Ammonite 1.2.1, 1.3.3 and 1.4.0.

3

There are 3 answers

0
Pablo Francisco Pérez Hidalgo On BEST ANSWER

Recent versions of ammonite offer simpler ways of adding repositories:

import $repo.`https://labs.consol.de/maven/repository`
0
david.perez On

a3var answer is correct. Following the same technique, I've managed to import sikulixapi 1.1.1:

interp.repositories() ++= Seq(coursier.MavenRepository("https://jitpack.io"))
import $ivy.`com.sikulix:sikulixapi:1.1.1`
0
Alex Archambault On

jxgrabkey:jxgrabkey:1.0 exists on a Maven repository, but per your mvnrepository link, it's not on Maven Central, but at http://labs.consol.de/maven/repository (see the target of the POM and JAR links).

So that extra repository has to be added to the Ammonite session, like

@ interp.repositories() ++= Seq(coursier.MavenRepository("https://labs.consol.de/maven/repository"))

@ import $ivy.`com.sikulix:sikulixapi:1.1.0`

Then the dependency can be added fine.

Note that I changed the protocol to https (http redirects to https, but protocol changing redirections aren't supported by coursier, which is the library that loads dependencies in Ammonite).