0

当有一个包含以下内容的脚本文件 (file.sc) 时:

import ammonite._, Resolvers._

val mock_client_repo = Resolver.Http("Unisay at bintray","http://dl.bintray.com/unisay/maven",MavenPattern,true)

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

import $ivy.`com.github.unisay::mockserver-client-scala:0.2.0`

import org.mockserver.client.server.MockServerClient
import com.github.unisay.mockserver.scala.DSL.Statuses._
import com.github.unisay.mockserver.scala.DSL._

val port = 3000
val host = "127.0.0.1"
implicit val server = new MockServerClient(host,port)

forAnyRequest respond Ok

我试图执行如下:amm files.sc
我收到以下错误:

编译 file.sc :: 加载设置 :: url = jar:file:/usr/local/bin/amm!/org/apache/ivy/core/settings/ivysettings.xml :: 解决依赖关系 :: com.github.unisay #mockserver-client-scala_2.11-caller;工作配置:[默认]

:: 问题总结 :: :::: WARNINGS module not found: com.github.unisay#mockserver-client-scala_2.11;0.2.0

==== 本地:试过

/home/eli/.ivy2/local/com.github.unisay/mockserver-client-scala_2.11/0.2.0/ivys/ivy.xml

-- artifact

com.github.unisay#mockserver-client-scala_2.11;0.2.0!mockserver-client-scala_2.11.jar:

/home/eli/.ivy2/local/com.github.unisay/mockserver-client-scala_2.11/0.2.0/jars/mockserver-client-scala_2.11.jar

==== m2: 试过

/home/eli/.m2/repository/com/github/unisay/mockserver-client-scala_2.11/0.2.0/ivy-0.2.0.xml

-- artifact

com.github.unisay#mockserver-client-scala_2.11;0.2.0!mockserver-client-scala_2.11.jar:

/home/eli/.m2/repository/com/github/unisay/mockserver-client-scala_2.11/0.2.0/mockserver-client-scala_2.11-0.2.0.jar

==== 中央:试过

http://repo1.maven.org/maven2/com/github/unisay/mockserver-client-scala_2.11/0.2.0/mockserver-client-scala_2.11-0.2.0.pom

-- artifact

com.github.unisay#mockserver-client-scala_2.11;0.2.0!mockserver-client-scala_2.11.jar:

http://repo1.maven.org/maven2/com/github/unisay/mockserver-client-scala_2.11/0.2.0/mockserver-client-scala_2.11-0.2.0.jar

:: 使用详细或调试消息级别获取更多详细信息线程“主”ammonite.runtime.tools.IvyThing$IvyResolutionException 中的异常:无法解决常春藤依赖项未解决的依赖项:com.github.unisay#mockserver-client-scala_2.11;0.2 .0:未找到

但是,如果运行从 repl 中粘贴的相同代码副本,则一切正常。

我究竟做错了什么?

4

1 回答 1

0

http://ammonite.io/#Multi-stageScripts

默认情况下,脚本中的所有内容都作为单个块编译和执行。虽然您可以在脚本运行之前使用 Magic Imports 加载其他脚本或 Ivy 工件,但它们只能加载“硬编码”脚本或工件,并且不能根据某些运行时变量加载不同的脚本。

如果您想根据运行时值加载不同的脚本或 ivy 工件,您可以使用运行时等效的魔术导入:

  • import $cp变成interp.load.cp
  • import $file变成interp.load.module
  • import $ivy变成interp.load.ivy

在你的情况下,改变

import $ivy.`com.github.unisay::mockserver-client-scala:0.2.0`

interp.load.ivy("com.github.unisay" %% "mockserver-client-scala" % "0.2.0")
于 2018-08-30T06:40:18.557 回答