sbt / sbt-osgi

sbt plugin for creating OSGi bundles
Apache License 2.0
47 stars 43 forks source link

How to exclude libraries that are marked with Provided #67

Closed fbaierl closed 5 years ago

fbaierl commented 5 years ago

Is there a way to create a fat jar using the OsgiKeys.embeddedJars attribute, but to exclude libraries that are marked as "Provided", like e.g.:

libraryDependencies += "org.apache.logging.log4j" % "log4j-api" % "2.7" % Provided
libraryDependencies +=  "com.typesafe.akka" %% "akka-actor" % akkaVersion

In this case com.typesafe.akka should be included in the fat jar while org.apache.logging.log4j should not be compiled into the jar.

fbaierl commented 5 years ago

I found a way to achieve this:

OsgiKeys.embeddedJars := (Keys.externalDependencyClasspath in Compile).value.map(_.data).filter(
  file => {
    /*
     * Find configs for file and return false if it includes "test" or "provided"
     */
    libraryDependencies.value.map(x => { (x.name.toLowerCase, x.configurations.map(_.toLowerCase)) })
      .find { case (n, _) => file.getName.toLowerCase.contains(n) }
      .flatMap {case (_, c) => c} match {
      case x if x.contains("test") => false
      case x if x.contains("provided") => false
      case _ => true
    }
  })