5

I have something like this in my 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)

When I now use the sbt-assembly-plugin to create the assembly of something_with_deps_provided, it still puts the dependencies into the resulting jar, ignoring the provided. Is it possible to set a transitive dependency to provided later and if yes, how is it done?

rabejens
  • 7,594
  • 11
  • 56
  • 104
  • Have you figured it out ? I guess you could exclude said depedencies, and the add them back as provided, but it is kind of hacky. – GPI Nov 23 '16 at 15:26

1 Answers1

0

In cases like this, excludeDependencies can be used as described in SBT manual here:
Exclude Transitive Dependencies.

With your example:

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
      )
    }
  )

The dependencies from someDeps will no longer be included in the assembly JAR for something_with_deps_provided project.