我有以下简单的SBT文件
name := "TweetStream"
version := "1.0"
libraryDependencies += "org.apache.spark" %% "spark-core" % "1.5.2"
libraryDependencies += "org.apache.spark" %% "spark-streaming" % "1.5.2"
libraryDependencies += "com.google.code.gson" %% "gson" % "2.7"
libraryDependencies += "org.twitter4j" %% "twitter4j-core" % "4.0.4"
不知何故,SBT工具在maven存储库路径中添加了一个xxx_2.10,导致无法解析的依赖项,如下所示。
> compile
[info] Updating {file:/home/hduser/workspace/TweetStream/}tweetstream...
[info] Resolving com.google.code.gson#gson_2.10;2.7 ...
[warn] module not found: com.google.code.gson#gson_2.10;2.7
[warn] ==== local: tried
[warn] /home/hduser/.ivy2/local/com.google.code.gson/gson_2.10/2.7/ivys/ivy.xml
[warn] ==== jcenter: tried
[warn] https://jcenter.bintray.com/com/google/code/gson/gson_2.10/2.7/gson_2.10-2.7.pom
[warn] ==== public: tried
[warn] https://repo1.maven.org/maven2/com/google/code/gson/gson_2.10/2.7/gson_2.10-2.7.pom
[info] Resolving org.twitter4j#twitter4j-core_2.10;4.0.4 ...
[warn] module not found: org.twitter4j#twitter4j-core_2.10;4.0.4
[warn] ==== local: tried
[warn] /home/hduser/.ivy2/local/org.twitter4j/twitter4j-core_2.10/4.0.4/ivys/ivy.xml
[warn] ==== jcenter: tried
[warn] https://jcenter.bintray.com/org/twitter4j/twitter4j-core_2.10/4.0.4/twitter4j-core_2.10-4.0.4.pom
[warn] ==== public: tried
[warn] https://repo1.maven.org/maven2/org/twitter4j/twitter4j-core_2.10/4.0.4/twitter4j-core_2.10-4.0.4.pom
[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[warn] :: UNRESOLVED DEPENDENCIES ::
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[warn] :: com.google.code.gson#gson_2.10;2.7: not found
[warn] :: org.twitter4j#twitter4j-core_2.10;4.0.4: not found
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[warn]
[warn] Note: Unresolved dependencies path:
[warn] com.google.code.gson:gson_2.10:2.7 (/home/hduser/workspace/TweetStream/build.sbt#L6-7)
[warn] +- default:tweetstream_2.10:1.0
[warn] org.twitter4j:twitter4j-core_2.10:4.0.4 (/home/hduser/workspace/TweetStream/build.sbt#L7-8)
[warn] +- default:tweetstream_2.10:1.0
[trace] Stack trace suppressed: run last *:update for the full output.
[error] (*:update) sbt.ResolveException: unresolved dependency: com.google.code.gson#gson_2.10;2.7: not found
[error] unresolved dependency: org.twitter4j#twitter4j-core_2.10;4.0.4: not found
[error] Total time: 17 s, completed Jun 30, 2016 11:45:29 PM
我试着按照另一篇文章的建议删除下面的ivy文件夹,但是没有帮助。
~/.ivy2/cache$ rm -r commons-logging/
您没有指定Scala版本,它默认为2.10,这可能不是您想要的。我不知道你想要的依赖是否已经发布到2.10了。
另一件事是,Gson不像Scala库那样发布,所以你应该通过单个%
添加它。twitter4j不太清楚,但这个名字也表明它是Java库,而不是Scala库。在您的build.sbt
name := "TweetStream"
scalaVersion := "2.11.8" // provide Scala version
version := "1.0"
libraryDependencies += "org.apache.spark" %% "spark-core" % "1.5.2"
libraryDependencies += "org.apache.spark" %% "spark-streaming" % "1.5.2"
libraryDependencies += "com.google.code.gson" % "gson" % "2.7" // notice single `%` instead of `%%`
libraryDependencies += "org.twitter4j" % "twitter4j-core" % "4.0.4" // same here