11

我有一个非常经典build.sbt的 Play 2.3 Scala 项目,具有以下libraryDependencies设置:

libraryDependencies ++= Seq(
  "org.scalatestplus" % "play_2.10" % "1.1.0" % "test"
  "org.mockito" % "mockito-core" % "1.9.5" % "test"
)

lazy val portal = (project in file(".")).enablePlugins(PlayScala)

PlayScala插件添加specs2了“污染”类路径的依赖项,并使 IDE 中的良好导入更加困难。

如何从中删除依赖项libraryDependencies

4

2 回答 2

13

我通过将以下内容添加到我的解决了类似的问题Build.scala

def excludeSpecs2(module: ModuleID): ModuleID =
  module.excludeAll(ExclusionRule(organization = "org.specs2"))

val main = Project(appName, file("."))
  .enablePlugins(play.PlayScala)
  .settings(libraryDependencies ~= (_.map(excludeSpecs2)))
于 2014-06-18T04:37:12.693 回答
7

我成功了。感谢 Venkat,我知道排除项,但由于我自己没有声明依赖项,所以我不知道在哪里使用它。

很简单:自己重新声明插件添加的依赖:

libraryDependencies ++= Seq(
  "org.scalatestplus" % "play_2.10" % "1.1.0" % "test",
  "org.mockito" % "mockito-core" % "1.9.5" % "test",
  "com.typesafe.play" %% "play-test" % play.core.PlayVersion.current % "test" exclude("org.specs2", "specs2-core_2.10") exclude("org.specs2", "specs2-junit_2.10") exclude("org.specs2", "specs2-mock_2.10") exclude("org.specs2", "specs2-matcher-extra_2.10") exclude("org.specs2", "") exclude("com.novocode", "junit-interface") exclude("com.google.guava", "guava") exclude("com.google.code.findbugs", "jsr305")
)

也许不是很优雅,但它确实有效。

于 2014-06-18T00:00:13.400 回答