Search code examples
scalaapache-sparkdependency-managementsbt-assembly

How to exclude jar in final sbt assembly plugin


I need to exclude spark and test dependencies from my final assembly jar. I tried to use provider but it was not working.

libraryDependencies ++= Seq("org.apache.spark" % "spark-core_2.11" % "2.0.1" % "provided")

and execute sbt assembly.

Please help me resolve this issue.


Solution

  • Use exclude option of assembly plugin filtering by direct name or with contains

    assemblyExcludedJars in assembly := {
        val cp = (fullClasspath in assembly).value
        cp filter { f =>
          f.data.getName.contains("spark-core") ||
          f.data.getName == "spark-core_2.11-2.0.1.jar"
        }
      }