库中的类没有被提取

时间:2018-02-25 21:44:27

标签: scala intellij-idea

我的build.sbt文件中有各种库依赖项

  scalaVersion := "2.10.5",
  libraryDependencies ++= Seq(
    "org.scalatest" %% "scalatest" % "2.2.5" % "test",
    "org.apache.spark" %% "spark-core" % "1.6.1" % "provided",
    "commons-logging" % "commons-logging" % "1.2"
  ) map (_.excludeAll(
    ExclusionRule(organization = "org.slf4j"),
    ExclusionRule(organization = "log4j"),
    ExclusionRule(organization = "javax.servlet")
  )),
  libraryDependencies ++= Seq(("org.slf4j" % "slf4j-log4j12" % "1.7.10")
    .excludeAll(ExclusionRule(organization = "log4j"))),
  libraryDependencies += "log4j" % "log4j" % "1.2.16" % "test",

我可以在项目视图中的外部库中看到它们。

enter image description here

但是,Scala源文件中没有提取库中的类。 enter image description here

这是一个子模块。 enter image description here 并且依赖项在父级build.sbt中声明。代码在子项目中。

我试过了:

  1. 使缓存/重新启动无效......
  2. 删除.idea文件并重新导入
  3. 多次构建项目
  4. 任何帮助表示感谢。

1 个答案:

答案 0 :(得分:0)

还需要在子项目中明确添加依赖项。

例如,在项目根文件夹的build.sbt中,您可以设置:

val commonDependencies = Seq(
  "commons-io" % "commons-io" % "2.5"
  // other dependencies
)

val root = (project in file(".")).settings(
  libraryDependencies ++= commonDependencies,
  libraryDependencies ++= Seq(
    // dependencies only for project root
  )
)

val topWordsCounter = (project in file("top-words-counter"))
.settings(
  libraryDependencies ++= commonDependencies,
  libraryDependencies ++= Seq(
    // dependencies only for the sub project project top-words-counter
  )
)

希望这有帮助