简体   繁体   English

如何解决SBT的库依赖关系警告?

[英]How to troubleshoot SBT's library dependency warnings?

I'm trying to build a "hello world"-esque app that uses Spark streaming to stream data from a Kafka broker (this works), filters/processes this data, and pushes it to a (local) web browser using the Scalatra web framework and its supported web sockets functionality from Atmosphere. 我正在尝试构建一个类似“ hello world”的应用程序,该应用程序使用Spark流技术从Kafka代理流式传输数据(此方法有效),过滤/处理此数据,然后使用Scalatra Web将其推送至(本地)网络浏览器框架及其来自Atmosphere的受支持的Web套接字功能。 The Kafka/Spark chunk works independently, and the Scalatra/Atmosphere chunk also works independently. Kafka / Spark块独立工作,而Scalatra / Atmosphere块也独立工作。 It's when I try to bring the two halves together that I run into issues with library dependencies. 当我尝试将这两个部分放在一起时,我遇到了库依赖问题。

The real question: how do I go about selecting library versions for which Spark will play nice with Scalatra? 真正的问题:我该如何选择Spark在Scalatra上能很好发挥作用的库版本?

A bare bones Scalatra/Atmosphere app works fine as follows: 裸露的Scalatra / Atmosphere应用程序可以正常运行,如下所示:

organization := "com.example"
name := "example app"
version := "0.1.0"
scalaVersion := "2.12.2"

val ScalatraVersion = "2.5.+"

libraryDependencies ++= Seq(
  "org.json4s"                  %% "json4s-jackson"      % "3.5.2",
  "org.scalatra"                %% "scalatra"            % ScalatraVersion,
  "org.scalatra"                %% "scalatra-scalate"    % ScalatraVersion,
  "org.scalatra"                %% "scalatra-specs2"     % ScalatraVersion    % "test",
  "org.scalatra"                %% "scalatra-atmosphere" % ScalatraVersion,
  "org.eclipse.jetty"           %  "jetty-webapp"        % "9.4.6.v20170531"  % "provided",
  "javax.servlet"               %  "javax.servlet-api"   % "3.1.0"            % "provided"
)

enablePlugins(JettyPlugin)

But if I add new dependencies for Spark and Spark streaming, and knock the Scala version down to 2.11 (required for Spark-Kafka streaming): 但是,如果我为Spark和Spark流添加新的依赖项,并将Scala版本降低到2.11(Spark-Kafka流需要):

organization := "com.example"
name := "example app"
version := "0.1.0"
scalaVersion := "2.11.8"

val ScalatraVersion = "2.5.+"
val SparkVersion = "2.2.0"

libraryDependencies ++= Seq(
  "org.json4s"                  %% "json4s-jackson"      % "3.5.2",
  "org.scalatra"                %% "scalatra"            % ScalatraVersion,
  "org.scalatra"                %% "scalatra-scalate"    % ScalatraVersion,
  "org.scalatra"                %% "scalatra-specs2"     % ScalatraVersion    % "test",
  "org.scalatra"                %% "scalatra-atmosphere" % ScalatraVersion,
  "org.eclipse.jetty"           %  "jetty-webapp"        % "9.4.6.v20170531"  % "provided",
  "javax.servlet"               %  "javax.servlet-api"   % "3.1.0"            % "provided"
)

libraryDependencies ++= Seq(
  "org.apache.spark" %% "spark-core" % SparkVersion,
  "org.apache.spark" %% "spark-streaming" % SparkVersion,
  "org.apache.spark" %% "spark-streaming-kafka-0-8" % SparkVersion
)

enablePlugins(JettyPlugin)

The code compiles, but I get SBT's eviction warning: 代码可以编译,但是我收到SBT的驱逐警告:

[warn] There may be incompatibilities among your library dependencies.
[warn] Here are some of the libraries that were evicted:
[warn]  * org.json4s:json4s-jackson_2.11:3.2.11 -> 3.5.3
[warn] Run 'evicted' to see detailed eviction warnings

Then finally, when Jetty tries to run the web server, it fails with this error: 最后,当Jetty尝试运行Web服务器时,它失败并显示以下错误:

WARN:oejuc.AbstractLifeCycle:main: FAILED org.eclipse.jetty.annotations.ServletContainerInitializersStarter@53fb3dab: java.lang.NoClassDefFoundError: com/sun/jersey/spi/inject/InjectableProvider
java.lang.NoClassDefFoundError: com/sun/jersey/spi/inject/InjectableProvider

How do I get to the bottom of this? 我该怎么做? I'm new to the Scala world, and the intricacies of dependencies are blowing my mind. 我是Scala世界的新手,并且错综复杂的依赖让我震惊。

One way to remove the eviction warning is to add the library dependency with the required version using dependencyOverrides 删除驱逐警告的一种方法是使用dependencyOverrides将库依赖项与所需版本一起添加

try to add the following in your SBT file and re-build the application 尝试在您的SBT文件中添加以下内容,然后重新生成应用程序

dependencyOverrides += "org.json4s" % "json4s-jackson_2.11" % "3.5.3"

Check SBT documentation here 在此处查看SBT文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM