防止SBT脱机运行的Logback依赖项

时间:2014-04-11 18:29:09

标签: scala sbt ivy logback

这是previous question的改进,更接近问题。

我试图确认我可以离线运行我的SBT项目。我可以,除非logback是我的libraryDependencies之一。为什么logback会触发问题?我做了一个简单的例子,它只包含一个build.sbt和一个'hello world'应用...

build.sbt 与一堆随机依赖关系来证明这一点:

name := "testProject"

version := "0.0.1"

scalaVersion := "2.10.3"

libraryDependencies ++= Seq(
    "org.apache.commons" % "commons-math3" % "3.2",
    "com.amazonaws" % "aws-java-sdk" % "1.4.0.1",
    "ch.qos.logback" % "logback-classic" % "1.1.1",
    "com.typesafe.akka" %% "akka-actor" % "2.3.1", 
    "com.typesafe.akka" %% "akka-remote" % "2.3.1",
    "org.scalaz" %% "scalaz-core" % "7.0.3"
)

我的步骤

  1. 删除项目中的~/.ivy2~/.sbttarget/,以确保
  2. 确保已连接到互联网,并执行sbt run。我的hello world成功运行
  3. 断开互联网连接
  4. sbt clean
  5. sbt run。构建失败,并将logback作为未解析的依赖项
  6. 再次删除logback依赖关系和sbt run。 Hello world运行。
  7. 这是第5步中的错误:

    [info] Resolving ch.qos.logback#logback-classic;1.1.1 ...
    [warn] Host repo1.maven.org not found. url=http://repo1.maven.org/maven2/ch/qos/logback/logback-classic/1.1.1/logback-classic-1.1.1.pom
    [info] You probably access the destination server through a proxy server that is not well configured.
    [warn]  module not found: ch.qos.logback#logback-classic;1.1.1
    [warn] ==== local: tried
    [warn]   /home/user/.ivy2/local/ch.qos.logback/logback-classic/1.1.1/ivys/ivy.xml
    [warn] ==== public: tried
    [warn]   http://repo1.maven.org/maven2/ch/qos/logback/logback-classic/1.1.1/logback-classic-1.1.1.pom
    [info] Resolving org.fusesource.jansi#jansi;1.4 ...
    [warn]  ::::::::::::::::::::::::::::::::::::::::::::::
    [warn]  ::          UNRESOLVED DEPENDENCIES         ::
    [warn]  ::::::::::::::::::::::::::::::::::::::::::::::
    [warn]  :: ch.qos.logback#logback-classic;1.1.1: not found
    [warn]  ::::::::::::::::::::::::::::::::::::::::::::::
    sbt.ResolveException: unresolved dependency: ch.qos.logback#logback-classic;1.1.1: not found
    

    更新

    在SBT中使用last命令,有一个用于依赖项解析的 lot 调试信息。以下是Akka成功解决的一个例子:

    [info] Resolving com.typesafe.akka#akka-actor_2.10;2.3.1 ...
    [debug] sbt-chain: Checking cache for: dependency: com.typesafe.akka#akka-actor_2.10;2.3.1 {compile=[default(compile)]}
    [debug] sbt-chain: module revision found in cache: com.typesafe.akka#akka-actor_2.10;2.3.1
    [debug]     local: revision in cache: com.typesafe.akka#akka-actor_2.10;2.3.1
    [debug]     found com.typesafe.akka#akka-actor_2.10;2.3.1 in sbt-chain
    [debug] == resolving dependencies testproject#testproject_2.10;0.0.1->com.typesafe.akka#akka-actor_2.10;2.3.1 [compile->runtime]
    [debug] == resolving dependencies testproject#testproject_2.10;0.0.1->com.typesafe.akka#akka-actor_2.10;2.3.1 [compile->compile]
    [debug] == resolving dependencies com.typesafe.akka#akka-actor_2.10;2.3.1->org.scala-lang#scala-library;2.10.3 [compile->master(*)]
    [debug] == resolving dependencies com.typesafe.akka#akka-actor_2.10;2.3.1->org.scala-lang#scala-library;2.10.3 [compile->compile(*)]
    [debug] == resolving dependencies com.typesafe.akka#akka-actor_2.10;2.3.1->com.typesafe#config;1.2.0 [compile->master(*)]
    

    这是Logback的失败:

    [info] Resolving ch.qos.logback#logback-classic;1.1.1 ...
    [debug] sbt-chain: Checking cache for: dependency: ch.qos.logback#logback-classic;1.1.1 {compile=[default(compile)]}
    [debug]         tried /home/user/.ivy2/local/ch.qos.logback/logback-classic/1.1.1/ivys/ivy.xml
    [debug]     local: no ivy file found for ch.qos.logback#logback-classic;1.1.1
    [debug]         tried http://repo1.maven.org/maven2/ch/qos/logback/logback-classic/1.1.1/logback-classic-1.1.1.pom
    [warn] Host repo1.maven.org not found. url=http://repo1.maven.org/maven2/ch/qos/logback/logback-classic/1.1.1/logback-classic-1.1.1.pom
    [info] You probably access the destination server through a proxy server that is not well configured.
    [debug]     public: no ivy file found for ch.qos.logback#logback-classic;1.1.1
    [warn]  module not found: ch.qos.logback#logback-classic;1.1.1
    [warn] ==== local: tried
    [warn]   /home/user/.ivy2/local/ch.qos.logback/logback-classic/1.1.1/ivys/ivy.xml
    [warn] ==== public: tried
    [warn]   http://repo1.maven.org/maven2/ch/qos/logback/logback-classic/1.1.1/logback-classic-1.1.1.pom
    

    我可以在缓存中确认以下文件(而不是'〜/ .ivy / local'文件夹):

    ~/.ivy2/cache/ch.qos.logback/logback-classic$ ls
    ivy-1.1.1.xml  ivy-1.1.1.xml.original  ivydata-1.1.1.properties  jars
    

3 个答案:

答案 0 :(得分:1)

它无法在您当地的常春藤缓存中找到它,修复该问题并解决了您的问题。

尝试清除你的常春藤缓存,也许它已经腐败了。

答案 1 :(得分:1)

当我尝试它时,文件确实从〜/ .ivy2 / cache解析。我没有〜/ .ivy2 / local因为我不在本地发布。您是否有可能有一个ivysettings.xml文件(在Linux上,尝试locate ivysettings.xml)与一些Ivy cache attribute混淆,如resolutionCacheDir?为什么你只对那个罐子有问题仍然是一个谜......

更新:这似乎是SBT 0.13.1的回归;它的工作频率为0.13.0,正如OP自己发现的那样(见他的答案),它在0.13.2中得到了修正。

答案 2 :(得分:0)

SBT 0.13.2在这个问题发布3天后发布,似乎解决了这个问题。我不知道这是否是一个已知问题,但为SBT 0.13.2列出的更改包括

  

解决问题,常春藤+。依赖范围不正确   翻译成maven。