库中的类没有被提取

问题描述 投票:0回答:1

我的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. 多次建设项目

任何帮助赞赏。

scala intellij-idea
1个回答
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
  )
)

希望这可以帮助

© www.soinside.com 2019 - 2024. All rights reserved.