scalaintellij-ideasbt-assembly

How to change Provided dependencies when using Intellij with SBT?


My build.sbt looks like this:

libraryDependencies ++= Seq(
  "org.apache.hadoop" % "hadoop-aws" % sparkVersion % Provided,
  "org.apache.spark" %% "spark-core" % sparkVersion % Provided,
  "org.apache.spark" %% "spark-sql" % sparkVersion % Provided,
  "org.scala-lang" % "scala-library" % scalaVersion.value % Provided
)

While running my application from Intellij, I get NoClassDefFoundError exceptions because it cannot find spark libraries. So when using Intellij, I need:

libraryDependencies ++= Seq(
  "org.apache.hadoop" % "hadoop-aws" % sparkVersion,
  "org.apache.spark" %% "spark-core" % sparkVersion,
  "org.apache.spark" %% "spark-sql" % sparkVersion,
  "org.scala-lang" % "scala-library" % scalaVersion.value % Provided
)

But that causes the final flat jar to be very big.

How to have different list of Provided dependencies depending whether using Intellij or not?


Solution

  • The solution for my use case was to check IntelliJ Add dependencies with "provided" scope to classpath option. Found it here:
    How to work efficiently with SBT, Spark and "provided" dependencies?

    Since UI has changed, here are the screenshots for Intellij 2021.2.3:

    After selecting it, you should see: