SBT:如何将依赖项的传递依赖项设置为稍后“提供”?

rab*_*ens 5 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)
Run Code Online (Sandbox Code Playgroud)

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

小智 0

在这种情况下,excludeDependencies可以按照 SBT 手册中的描述使用:
排除传递依赖

以你的例子:

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
      )
    }
  )
Run Code Online (Sandbox Code Playgroud)

someDeps项目的程序集 JAR 中将不再包含依赖项something_with_deps_provided