SBT:如何在以后将依赖关系的传递依赖关系设置为“提供”?

时间:2015-12-01 08:06:50

标签: sbt sbt-assembly

我的build.sbt

中有类似的内容
lazy val someDeps = Seq(
  libraryDependencies += "com.example" %% "foo" % "1.3.37",
  // more
)

lazy val some_library = project.in(file("libs/somelibrary")).
  settings(commonSettings).
  settings(
    // project-specific settings
    libraryDependencies ++= someDeps
  )

lazy val something_with_deps_provided = project.in(file("swdp")).
  settings(commonSettings).
  settings(
    // project-specific settings
    libraryDependencies ++= someDeps.map(d => d % "provided")
  ).dependsOn(some_library)

当我现在使用sbt-assembly-plugin创建something_with_deps_provided的程序集时,它仍会将依赖项放入生成的jar中,忽略provided。以后是否可以将传递依赖性设置为provided,如果是,它是如何完成的?

1 个答案:

答案 0 :(得分:0)

在这种情况下,可以按照以下说明使用excludeDependencies SBT手册在这里:
Exclude Transitive Dependencies

以您的示例为例:

lazy val something_with_deps_provided = project.in(file("swdp"))
  .settings(commonSettings)
  .dependsOn(some_library)
  .settings(
    // project-specific settings
    excludeDependencies ++= someDeps.map { d => 
      ExclusionRule(
        organization = d.organization,
        name         = d.name
      )
    }
  )

来自someDeps的依赖项将不再包含在 something_with_deps_provided项目的程序集JAR。