【问题标题】:SBT doesn't find file in local maven repository although it's thereSBT 在本地 maven 存储库中找不到文件,尽管它在那里
【发布时间】:2012-06-02 03:38:55
【问题描述】:

我的本​​地存储库中的 maven 依赖项存在问题。

SBT 找不到它。已将日志级别设置为调试,但没有任何新内容。

文件在存储库中。我将粘贴路径从控制台复制到文件资源管理器,它们就在那里。

输出:

[debug]          trying file://c:/Users/userz/.m2/repository/com/twitter/naggati/2.0.0/naggati-2.0.0.pom

[debug]                 tried file://c:/Users/userz/.m2/repository/com/twitter/naggati/2.0.0/naggati-2.0.0.pom

[debug]         Local Maven Repository: resource not reachable for com/twitter#naggati;2.0.0: res=file://c:/Users/userz/.m2/repository/com/twitter/naggati/2.0
.0/naggati-2.0.0.pom

[debug]          trying file://c:/Users/userz/.m2/repository/com/twitter/naggati/2.0.0/naggati-2.0.0.jar

[debug]                 tried file://c:/Users/userz/.m2/repository/com/twitter/naggati/2.0.0/naggati-2.0.0.jar

[debug]         Local Maven Repository: resource not reachable for com/twitter#naggati;2.0.0: res=file://c:/Users/userz/.m2/repository/com/twitter/naggati/2.0
.0/naggati-2.0.0.jar

[debug]         Local Maven Repository: no ivy file nor artifact found for com.twitter#naggati;2.0.0

编辑:我在 project/build 中使用 scala 文件添加了路径,如http://code.google.com/p/simple-build-tool/wiki/LibraryManagement中所述

"如果你把它添加为仓库,sbt 可以搜索你本地的 Maven 仓库:"

val mavenLocal = "Local Maven Repository" at "file://"+Path.userHome+"/.m2/repository"

这使得 sbt 在本地存储库中查找。之前没有。

所以 scala 文件看起来像这样:

import sbt._

class Foo(info: ProjectInfo) extends DefaultProject(info) {

val mavenLocal = "Local Maven Repository" at "file://c:/Users/userz/.m2/repository"

}

(我硬编码 Path.userHome 以排除可能的错误原因。正如预期的那样,它没有改变任何东西)。

【问题讨论】:

  • 你必须将本地 maven repo 添加到你的 build.sbt
  • 存储库已添加,否则脚本不会在那里查找文件。
  • 告诉 sbt 寻找你的依赖的那一行是怎样的?如果你有类似 ... -> 默认的东西,请从那里删除默认值。
  • 其实我没有使用 build.sbt。我正在使用 code.google.com/p/simple-build-tool/wiki/LibraryManagement 中描述的 scala 文件。用更多细节编辑了我的帖子。
  • ixx:这是 SBT 0.7.x,它是旧版本。如果可能,您应该更新到 [SBT 0.11.x])github.com/harrah/xsbt/wiki)。

标签: scala maven sbt


【解决方案1】:

当您定义了项目时请注意,您需要在设置中包含解析器。不会识别全局解析器。

例子:

lazy val core = (project in file("core")).
  settings(commonSettings: _*).
  settings(
    resolvers += Resolver.mavenLocal,
    name := "Core",
    libraryDependencies := coreDependencies
  )

【讨论】:

  • 对我不起作用,尽管它可能与项目有关
  • 感谢 Dyin,它成功了。为 commonSettings 添加了解析器,现在所有定义的项目都可以查看本地 maven repo 的依赖项。
【解决方案2】:

只需在 build.scala 或 build.sbt 文件中添加这一行

resolvers += Resolver.mavenLocal

【讨论】:

  • 那是哪个 sbt?我将它与 0.13.11 一起使用,效果很好。
  • resolvers in Global := Resolver.mavenLocal 为我工作。
  • 天啊,我已经搜索了一个小时来寻找这个完美的解决方案!谢谢
  • @retronym,我认为您的意思是“全局解析器 += Resolver.mavenLocal”
  • 对于 SBT 1.3.x,它是 ThisBuild / resolvers += Resolver.mavenLocal
【解决方案3】:

file: 说明符后需要三个斜杠。这是因为在第二个和第三个斜杠之间,您有一个可选的主机名。 Wikipediafile: URL 有很好的解释

您遇到了问题,因为 "file://"+Path.userHome+"/.m2/repository" 的典型模式假定 Unix 文件系统,其中路径以 / 开头,不包含 :,并且通常不包含空格。

要在 Windows 和 Linux/Unix 上工作的非硬编码路径,请使用:

"Local Maven" at Path.userHome.asFile.toURI.toURL + ".m2/repository"

【讨论】:

  • 未定义项目并且添加到项目中也不起作用
【解决方案4】:

要使其适用于较新版本的 sbt,请将以下内容添加到 build.sbt:

resolvers += "Local Maven Repository" at "file:///"+Path.userHome+"/.m2/repository"

【讨论】:

  • 无论我做什么,在执行 sbt compile 时仍然会出现此错误:[warn] ::::::::::::::::::::::: :::::::::::::::::::::: [警告] :: 未解决的依赖性 :: [警告] :::::::::::::::: :::::::::::::::::::::::::::::: [警告] :: com.sanoma.cda#maxmind-geoip2-scala_2.11;1.3 .2: 未找到 [警告] ::::::::::::::::::::::::::::::::::::::::::: :::: [trace] 堆栈跟踪被抑制:运行最后一个 :update 以获得完整输出。 [错误] (:update) sbt.ResolveException: unresolved dependency: com.sanoma.cda#maxmind-geoip2-scala_2.11;1.3.2: not found
  • 我用过resolvers in Global += "Local Maven Repository" at "file://" + Path.userHome + "/.m2/repository"
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-04-17
  • 1970-01-01
  • 2014-06-28
  • 2018-03-01
  • 2014-08-10
  • 2015-06-15
  • 2014-03-01
相关资源
最近更新 更多