scala SBT 在本地 Maven 存储库中找不到文件,尽管它在那里
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10773319/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
SBT doesn't find file in local maven repository although it's there
提问by Ixx
I'm having problems with a maven dependency which is in my local respository.
我在本地存储库中遇到了 Maven 依赖项的问题。
SBT can't find it. Already set log level to debug, but not getting anything new.
SBT 找不到。已将日志级别设置为调试,但没有获得任何新信息。
The files are in the repository. I copy paste paths from the console to file explorer and they are there.
文件位于存储库中。我将粘贴路径从控制台复制到文件资源管理器,它们就在那里。
The output:
输出:
[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
Edit: I added the path using scala file in project/buildlike described in http://code.google.com/p/simple-build-tool/wiki/LibraryManagement
编辑:我在项目/构建中使用 scala 文件添加了路径,如http://code.google.com/p/simple-build-tool/wiki/LibraryManagement 中所述
"sbt can search your local Maven repository if you add it as a repository:"
“如果您将其添加为存储库,则 sbt 可以搜索您本地的 Maven 存储库:”
val mavenLocal = "Local Maven Repository" at "file://"+Path.userHome+"/.m2/repository"
That made sbt look in the local repository. Before it didn't.
这使得 sbt 在本地存储库中查找。在它没有之前。
So the scala file looks like this:
所以scala文件看起来像这样:
import sbt._
class Foo(info: ProjectInfo) extends DefaultProject(info) {
val mavenLocal = "Local Maven Repository" at "file://c:/Users/userz/.m2/repository"
}
(I hardcoded Path.userHome to exclude possible error reason. As expected it didn't change anything).
(我硬编码 Path.userHome 以排除可能的错误原因。正如预期的那样,它没有改变任何东西)。
采纳答案by leedm777
You need three slashes after the file:specifier. This is because between the second and third slash, you have an optional hostname. Wikipediahas a good explanation of file:URL's
file:说明符后需要三个斜杠。这是因为在第二个和第三个斜杠之间,您有一个可选的主机名。维基百科对file:URL有很好的解释
You're having a problem because the typical pattern of "file://"+Path.userHome+"/.m2/repository"assumes a Unix filesystem, where the path begins with a /, contains no :, and usually contains no spaces.
您遇到了问题,因为"file://"+Path.userHome+"/.m2/repository"假设 Unix 文件系统的典型模式,其中路径以 a 开头/,不包含:,并且通常不包含空格。
To have a non-hardcoded path that works on both Windows and Linux/Unix, use:
要拥有适用于 Windows 和 Linux/Unix 的非硬编码路径,请使用:
"Local Maven" at Path.userHome.asFile.toURI.toURL + ".m2/repository"
回答by Ben Rhouma Zied
Just add this line in the build.scala or build.sbt file
只需在 build.scala 或 build.sbt 文件中添加这一行
resolvers += Resolver.mavenLocal
回答by Marius
To get this to work for newer versions of sbt, add the following to build.sbt:
要使其适用于较新版本的 sbt,请将以下内容添加到 build.sbt:
resolvers += "Local Maven Repository" at "file:///"+Path.userHome+"/.m2/repository"
回答by Dyin
Watch out when you have a project defined, you'll need to include the resolver in the settings. Global resolver will not be identified.
当你定义了一个项目时要小心,你需要在设置中包含解析器。不会识别全局解析器。
Example:
例子:
lazy val core = (project in file("core")).
settings(commonSettings: _*).
settings(
resolvers += Resolver.mavenLocal,
name := "Core",
libraryDependencies := coreDependencies
)

