尝试使用 Scala + Spark 构建自包含应用程序时未解决的依赖项错误

Unresolved dependencies errors when trying to build self-contained application with Scala + Spark

我正在尝试遵循 Self-Contained Applications Tutorial 并尝试使用 sbtscala 进行构建,但是我 运行 在调用 [=16= 时出现以下错误] 来自 C:\Users[=17=]926133\test:

[info] Set current project to Simple Project (in build file:/C:/Users/00926133/test/)
[info] Updating {file:/C:/Users/00926133/test/}test...
[info] Resolving org.scala-lang#scala-library;2.10.4 ...
[info] Resolving org.scala-lang#scala-library;2.10.4 ...
[error] Unable to find credentials for [ @ XXXX].
[info] Resolving org.apache.spark#spark-core_2.10;1.4.0 ...
[info] Resolving org.apache.spark#spark-core_2.10;1.4.0 ...
[info] Resolving org.scala-lang#scala-compiler;2.10.4 ...
[info] Resolving org.scala-lang#scala-compiler;2.10.4 ...
[warn]  ::::::::::::::::::::::::::::::::::::::::::::::
[warn]  ::          UNRESOLVED DEPENDENCIES         ::
[warn]  ::::::::::::::::::::::::::::::::::::::::::::::
[warn]  :: org.scala-lang#scala-library;2.10.4: java.util.NoSuchElementException
[warn]  :: org.apache.spark#spark-core_2.10;1.4.0: java.util.NoSuchElementException
[warn]  :: org.scala-lang#scala-compiler;2.10.4: java.util.NoSuchElementException
[warn]  ::::::::::::::::::::::::::::::::::::::::::::::
[warn] 
[warn]  Note: Unresolved dependencies path:
[warn]      org.scala-lang:scala-library:2.10.4 ((sbt.Classpaths) Defaults.scala#L1203)
[warn]        +- simple-project:simple-project_2.10:1.0
[warn]      org.apache.spark:spark-core_2.10:1.4.0 (C:\Users[=10=]926133\test\simple.sbt#L7-8)
[warn]        +- simple-project:simple-project_2.10:1.0
[warn]      org.scala-lang:scala-compiler:2.10.4
[warn]        +- simple-project:simple-project_2.10:1.0
sbt.ResolveException: unresolved dependency: org.scala-lang#scala-library;2.10.4: java.util.NoSuchElementException
unresolved dependency: org.apache.spark#spark-core_2.10;1.4.0: java.util.NoSuchElementException
unresolved dependency: org.scala-lang#scala-compiler;2.10.4: java.util.NoSuchElementException
    at sbt.IvyActions$.sbt$IvyActions$$resolve(IvyActions.scala:291)
    at sbt.IvyActions$$anonfun$updateEither.apply(IvyActions.scala:188)
    at sbt.IvyActions$$anonfun$updateEither.apply(IvyActions.scala:165)
    at sbt.IvySbt$Module$$anonfun$withModule.apply(Ivy.scala:155)
    at sbt.IvySbt$Module$$anonfun$withModule.apply(Ivy.scala:155)
    at sbt.IvySbt$$anonfun$withIvy.apply(Ivy.scala:132)
    at sbt.IvySbt.sbt$IvySbt$$action(Ivy.scala:57)
    at sbt.IvySbt$$anon.call(Ivy.scala:65)
    at xsbt.boot.Locks$GlobalLock.withChannel(Locks.scala:93)
    at xsbt.boot.Locks$GlobalLock.xsbt$boot$Locks$GlobalLock$$withChannelRetries(Locks.scala:78)
    at xsbt.boot.Locks$GlobalLock$$anonfun$withFileLock.apply(Locks.scala:97)
    at xsbt.boot.Using$.withResource(Using.scala:10)
    at xsbt.boot.Using$.apply(Using.scala:9)
    at xsbt.boot.Locks$GlobalLock.ignoringDeadlockAvoided(Locks.scala:58)
    at xsbt.boot.Locks$GlobalLock.withLock(Locks.scala:48)
    at xsbt.boot.Locks$.apply0(Locks.scala:31)
    at xsbt.boot.Locks$.apply(Locks.scala:28)
    at sbt.IvySbt.withDefaultLogger(Ivy.scala:65)
    at sbt.IvySbt.withIvy(Ivy.scala:127)
    at sbt.IvySbt.withIvy(Ivy.scala:124)
    at sbt.IvySbt$Module.withModule(Ivy.scala:155)
    at sbt.IvyActions$.updateEither(IvyActions.scala:165)
    at sbt.Classpaths$$anonfun$sbt$Classpaths$$work.apply(Defaults.scala:1369)
    at sbt.Classpaths$$anonfun$sbt$Classpaths$$work.apply(Defaults.scala:1365)
    at sbt.Classpaths$$anonfun$doWork$$anonfun.apply(Defaults.scala:1399)
    at sbt.Classpaths$$anonfun$doWork$$anonfun.apply(Defaults.scala:1397)
    at sbt.Tracked$$anonfun$lastOutput.apply(Tracked.scala:37)
    at sbt.Classpaths$$anonfun$doWork.apply(Defaults.scala:1402)
    at sbt.Classpaths$$anonfun$doWork.apply(Defaults.scala:1396)
    at sbt.Tracked$$anonfun$inputChanged.apply(Tracked.scala:60)
    at sbt.Classpaths$.cachedUpdate(Defaults.scala:1419)
    at sbt.Classpaths$$anonfun$updateTask.apply(Defaults.scala:1348)
    at sbt.Classpaths$$anonfun$updateTask.apply(Defaults.scala:1310)
    at scala.Function1$$anonfun$compose.apply(Function1.scala:47)
    at sbt.$tilde$greater$$anonfun$$u2219.apply(TypeFunctions.scala:40)
    at sbt.std.Transform$$anon.work(System.scala:63)
    at sbt.Execute$$anonfun$submit$$anonfun$apply.apply(Execute.scala:226)
    at sbt.Execute$$anonfun$submit$$anonfun$apply.apply(Execute.scala:226)
    at sbt.ErrorHandling$.wideConvert(ErrorHandling.scala:17)
    at sbt.Execute.work(Execute.scala:235)
    at sbt.Execute$$anonfun$submit.apply(Execute.scala:226)
    at sbt.Execute$$anonfun$submit.apply(Execute.scala:226)
    at sbt.ConcurrentRestrictions$$anon$$anonfun.apply(ConcurrentRestrictions.scala:159)
    at sbt.CompletionService$$anon.call(CompletionService.scala:28)
    at java.util.concurrent.FutureTask.run(FutureTask.java:262)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
    at java.util.concurrent.FutureTask.run(FutureTask.java:262)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:745)
[error] (*:update) sbt.ResolveException: unresolved dependency: org.scala-lang#scala-library;2.10.4: java.util.NoSuchElementException
[error] unresolved dependency: org.apache.spark#spark-core_2.10;1.4.0: java.util.NoSuchElementException
[error] unresolved dependency: org.scala-lang#scala-compiler;2.10.4: java.util.NoSuchElementException
[error] Total time: 1 s, completed Jun 26, 2015 9:13:40 AM

我在 运行ning spark-shellscala 以及 pythonR 的 spark 示例中取得了成功。我还尝试删除 .ivy 文件夹。


我的simple.sbt文件:

name := "Simple Project"

version := "1.0"

scalaVersion := "2.10.4"

libraryDependencies += "org.apache.spark" % "spark-core_2.10" % "1.4.0"

其他信息

我浏览了几篇 Stack Overflow 帖子,但是 none 中显示的解决方案似乎让我有所了解。


更新
我能够确认这是与代理相关的问题。但是,我仍然无法在我的代理后面构建。这是在 Windows 上,我有以下内容:

环境变量

SBT_OPTS = -Dhttp.proxyHost=<myhost> -Dhttp.proxyPort=<myport> -Dhttp.proxyUser=<myuser> -Dhttp.proxyPassword=<mypassword> -Dhttps.proxyHost=<myhost> -Dhttps.proxyPort=<myport> -Dhttps.proxyUser=<myuser> -Dhttps.proxyPassword=<mypassword> 
JAVA_OPTS = -Dhttp.proxyHost=<myhost> -Dhttp.proxyPort=<myport> -Dhttp.proxyUser=<myuser> -Dhttp.proxyPassword=<mypassword> -Dhttps.proxyHost=<myhost> -Dhttps.proxyPort=<myport> -Dhttps.proxyUser=<myuser> -Dhttps.proxyPassword=<mypassword>

我还将以下行添加到位于 ..\sbt\conf 下的 sbtconfig.txt 中:

-Dhttp.proxyHost=<myhost>
-Dhttp.proxyPort=<myport>
-Dhttp.proxyUser=<myuser>
-Dhttp.proxyPassword=<mypassword>
-Dhttps.proxyHost=<myhost>
-Dhttps.proxyPort=<myport>
-Dhttps.proxyUser=<myuser>
-Dhttps.proxyPassword=<mypassword>

任何能够 (a) 通俗易懂地解释 sbt package 正在做什么,(b) 如何解释 simple.sbt 文件,and/or (c) 弄清楚如何解决 [error] Unable to find credentials for [ @ XXXX ] -- XXXX 是我工作的代理服务器。

我在 SBT source code 中找到了您第一个错误的源代码(按时间顺序排列)并附有评论 "We're guaranteed to only get here if Ivy's authentication fails"。由于剩余的错误是无法找到依赖项,因此看起来是代理导致了问题。

你看到问题了吗How to use sbt from behind proxy?你试过那些步骤了吗?

Ivy 被 SBT 用于在本地缓存依赖项,因此一旦您获取了特定依赖项的特定版本,您就无需再次访问 Internet 获取它。在 Windows,您可以在 C:\Users\<User Name>\.ivy2

查看 Ivy 缓存的内容

看起来 SBT 无法通过贵公司的代理,导致它无法获取第三方依赖项,从而导致构建失败。如果您还没有尝试过,请尝试在 SBT 命令行或环境变量中设置代理配置。由于您使用的是 Windows,只需将 -Dhttp.proxyHost=yourserver -Dhttp.proxyPort=port ... 添加到 SBT 命令行即可。确保根据代理的要求添加所有必需的参数。 (需要 username/password 吗?)

SBT 是 Scala 的 "Simple Build Tool." SBT 文件是用 Scala 编写的。 SBT 中的 类 定义了运算符,这些运算符会导致您根据构建文件请求的构建操作。当您 运行 sbt package 时,您要求构建工具构建和打包当前项目。

Spark quick startsimple.sbt 文件进行了高层次的解释。 SBT构建文件一般会给出项目名称和版本,定义需要的Scala版本,列出第三方依赖,总的来说定义了整个构建和打包过程所需要的一切。