New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cannot add a resolver from within a script #491

Closed
dportabella opened this Issue Oct 25, 2016 · 15 comments

Comments

Projects
None yet
5 participants
@dportabella
Contributor

dportabella commented Oct 25, 2016

This works good:

$ amm
Loading...
@ val oss = Resolver.Http(
    "ambiata-oss",
    "https://ambiata-oss.s3-ap-southeast-2.amazonaws.com",
    IvyPattern,
    false
  )
@ interp.resolvers() = interp.resolvers() :+ oss
@ import $ivy.`com.ambiata::mundane:1.2.1-20141230225616-50fc792`
import $ivy.$

However, this fails:

cat >script <<'EOF'
import ammonite._, Resolvers._

val oss = Resolver.Http(
  "ambiata-oss",
  "https://ambiata-oss.s3-ap-southeast-2.amazonaws.com",
  IvyPattern,
  false
)

interp.resolvers() = interp.resolvers() :+ oss

import $ivy.`com.ambiata::mundane:1.2.1-20141230225616-50fc792`
EOF

$ amm script
Compiling script
:: loading settings :: url = jar:file:/usr/local/Cellar/ammonite-repl/0.7.8/bin/amm!/org/apache/ivy/core/settings/ivysettings.xml
:: resolving dependencies :: com.ambiata#mundane_2.11-caller;working
    confs: [default]

:: problems summary ::
:::: WARNINGS
        module not found: com.ambiata#mundane_2.11;1.2.1-20141230225616-50fc792

    ==== local: tried

      /Users/david/.ivy2/local/com.ambiata/mundane_2.11/1.2.1-20141230225616-50fc792/ivys/ivy.xml

      -- artifact com.ambiata#mundane_2.11;1.2.1-20141230225616-50fc792!mundane_2.11.jar:

      /Users/david/.ivy2/local/com.ambiata/mundane_2.11/1.2.1-20141230225616-50fc792/jars/mundane_2.11.jar

    ==== m2: tried

      /Users/david/.m2/repository/com/ambiata/mundane_2.11/1.2.1-20141230225616-50fc792/ivy-1.2.1-20141230225616-50fc792.xml

      -- artifact com.ambiata#mundane_2.11;1.2.1-20141230225616-50fc792!mundane_2.11.jar:

      /Users/david/.m2/repository/com/ambiata/mundane_2.11/1.2.1-20141230225616-50fc792/mundane_2.11-1.2.1-20141230225616-50fc792.jar

    ==== central: tried

      http://repo1.maven.org/maven2/com/ambiata/mundane_2.11/1.2.1-20141230225616-50fc792/mundane_2.11-1.2.1-20141230225616-50fc792.pom

      -- artifact com.ambiata#mundane_2.11;1.2.1-20141230225616-50fc792!mundane_2.11.jar:

      http://repo1.maven.org/maven2/com/ambiata/mundane_2.11/1.2.1-20141230225616-50fc792/mundane_2.11-1.2.1-20141230225616-50fc792.jar


:: USE VERBOSE OR DEBUG MESSAGE LEVEL FOR MORE DETAILS
Exception in thread "main" ammonite.runtime.tools.IvyThing$IvyResolutionException: failed to resolve ivy dependencies unresolved dependency: com.ambiata#mundane_2.11;1.2.1-20141230225616-50fc792: not found

For some reason, interp.resolvers() = interp.resolvers() :+ oss is not taken into accound when run from within a script.

Note: I need this to create a script with the #!/usr/bin/env amm header.

@Eli-Golin

This comment has been minimized.

@lihaoyi

This comment has been minimized.

Owner

lihaoyi commented Nov 15, 2016

The problem here is that the resolvers only get added when the code executes, but the import $ivy takes effect before the code executes.

A workaround would be to put the resolver-mangling into a separate compilation block, using @ to split the file in two:

import ammonite._, Resolvers._

val oss = Resolver.Http(
  "ambiata-oss",
  "https://ambiata-oss.s3-ap-southeast-2.amazonaws.com",
  IvyPattern,
  false
)

interp.resolvers() = interp.resolvers() :+ oss

@

import $ivy.`com.ambiata::mundane:1.2.1-20141230225616-50fc792`
...

Perhaps at some point we can add a magic import $resolver that can do this for us and let us avoid the annoying @

@dportabella

This comment has been minimized.

Contributor

dportabella commented Nov 15, 2016

cool, I didn't know about "compilation blocks"!
however I tried this and it fails with the same error.

@dportabella

This comment has been minimized.

Contributor

dportabella commented Nov 29, 2016

@Eli-Golin, does the solution proposed by @lihaoyi work for you?

@lihaoyi

This comment has been minimized.

Owner

lihaoyi commented Nov 29, 2016

sorry, haven't had time to look at this properly. I'm hoping that when @alexarchambault releases coursier 1.0.0 I can switch to it and all my ivy problems will magically go away... I don't actually know how ivy works

@hohonuuli

This comment has been minimized.

hohonuuli commented Jan 9, 2017

Just a note that I'm having the same issue. Using @ didn't fix it for me either. (Also, ammonite is fantastic BTW)

@drdozer

This comment has been minimized.

drdozer commented Jan 21, 2017

Is there a fix for this? I have a dependency on the postgres jdbc jar, in https://maven.atlassian.com/3rdparty/ and while i can load this in the REPL, I can't work out how to add the resolver in a script to get it to work.

@drdozer

This comment has been minimized.

drdozer commented Jan 21, 2017

A work-around is to manually load that dependency into your local maven cache:

mvn dependency:get -DrepoUrl=https://maven.atlassian.com/3rdparty/ -DgroupId=postgresql -DartifactId=postgresql -Dversion=9.4.1208-jdbc42-atlassian-hosted

lihaoyi added a commit that referenced this issue May 19, 2017

Properly run import hooks in multi-block scripts in the block they ar…
…e defined in, rather than all up-front at the top. Fixes #491

Both the main running sequence as well as the data-format of the cached metadata need to be updated to interleave the processing of import hooks and user code
@lihaoyi

This comment has been minimized.

Owner

lihaoyi commented May 19, 2017

Should be fixed in daa4768

@lihaoyi lihaoyi closed this May 19, 2017

lihaoyi added a commit that referenced this issue May 19, 2017

Properly run import hooks in multi-block scripts in the block they ar…
…e defined in, rather than all up-front at the top. Fixes #491

Both the main running sequence as well as the data-format of the cached metadata need to be updated to interleave the processing of import hooks and user code
@dportabella

This comment has been minimized.

Contributor

dportabella commented May 19, 2017

cool! i see the fix is committed in the "test" branch.
is it possible to get a notification when the fix is released?

@lihaoyi

This comment has been minimized.

Owner

lihaoyi commented May 19, 2017

Come hang out in the gitter channel or follow me on twitter and you'll get pinged =)

@lihaoyi

This comment has been minimized.

Owner

lihaoyi commented May 19, 2017

At some point, the Ammonite REPL will start pinging you about updated versions (#488) but that's for the future

@dportabella

This comment has been minimized.

Contributor

dportabella commented May 19, 2017

ok, thx!

@lihaoyi

This comment has been minimized.

Owner

lihaoyi commented May 21, 2017

@dportabella

This comment has been minimized.

Contributor

dportabella commented May 29, 2017

Cool! I confirm it works!
and so that this Web2Warc script!
helgeho/Web2Warc#2 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment