SBT无法解决依赖性问题

时间:2016-06-30 14:05:55

标签: scala sbt

我有以下简单的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

我已尝试按照其他帖子的建议删除以下常春藤文件夹,但它没有帮助。

~/.ivy2/cache$ rm -r commons-logging/

1 个答案:

答案 0 :(得分:6)

您没有指定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