2

I'm using ammonite (http://ammonite.io/) to write Scala scripts. It allows you to fetch remote dependencies via this kind of text:

import $ivy.`org.scalaz::scalaz-core:7.2.7`, scalaz._, Scalaz._

How do you use a local maven repo (sitting in e.g. ~/.m2), though?

Mohan
  • 7,302
  • 5
  • 32
  • 55

3 Answers3

4

It changed in v 1.7.1 Now the correct way to do this is like this :

import coursierapi.MavenRepository

interp.repositories.update(
  interp.repositories() ::: List(MavenRepository.of("https://some_repo"))
)

If you wish to link up a local repository, you can replace https://some_repo with file://path_to_local_rep

Thanks to @danslapman on github - here's the reference discussion https://github.com/lihaoyi/Ammonite/issues/1003

2

With many thanks to @sake92 on https://gitter.im/lihaoyi/Ammonite

#!/usr/bin/env amm

interp.repositories() ++= Seq(coursier.Cache.Dangerous.maven2Local)

@

import $ivy.`com.foo:artifact:1.3.0`

The @ forces the script to be compiled in two parts. Without it the extra repo will simply be ignored.

Mohan
  • 7,302
  • 5
  • 32
  • 55
1

There was an issue some time ago with a following PR that concluded that there quite often local Maven repository contains broken things, so it is not there by default.

However, later ability to add your own resolvers was added, probably sth like:

import coursier.MavenRepository

interp.repositories() ++= Seq(MavenRepository(
  "~/.m2/local"
))

should work.

Mateusz Kubuszok
  • 24,995
  • 4
  • 42
  • 64
  • Couldn't get it to work. Tried "~/.m2", "~/.m2/local", "~/.m2/repository". (The last being a path on my Macbook.) `import com.foo.bar.class` gives `object 'foo' is not a member of com`. – Mohan Sep 03 '18 at 13:44