使用ammonite repl进行Scala脚本编写

时间:2016-10-26 08:23:21

标签: scala ammonite

具有包含以下内容的脚本文件(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 :: loading settings :: url =   罐子:文件:在/ usr / local / bin目录/ AMM /org/apache/ivy/core/settings/ivysettings.xml   ::解决依赖关系::   com.github.unisay#mockserver-client-scala_2.11-caller; working confs:   [默认]

     

::问题摘要:::::找不到WARNINGS模块:   com.github.unisay#mockserver-客户scala_2.11; 0.2.0

     

==== local:尝试

     

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

-- artifact
     

com.github.unisay#mockserver-客户scala_2.11; 0.2.0 mockserver-客户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-客户scala_2.11; 0.2.0 mockserver-客户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-客户scala_2.11; 0.2.0 mockserver-客户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

     

::使用VERBOSE或调试消息级别获取更多详细信息   线程"主要" ammonite.runtime.tools.IvyThing $ IvyResolutionException:   无法解决ivy依赖关系未解决的依赖关系:   com.github.unisay#mockserver-client-scala_2.11; 0.2.0:not found

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

我做错了什么?

1 个答案:

答案 0 :(得分:0)

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

  

默认情况下,脚本中的所有内容都作为   单块。虽然可以使用Magic Imports加载其他脚本或   在脚本运行之前,常春藤制品只能加载“硬编码”   脚本或人工制品,例如加载不同的脚本,具体取决于   在某些运行时变量上。

     

如果要加载不同的脚本或常春藤工件,具体取决于   运行时值,您可以使用与魔术导入等效的运行时:

  • 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")