Conditional dependency settings in SBT using inTask(...)
<p>I am using spark and I want to be able to execute jobs both local and remotely from InteliJ. My dependency settings are </p>

<pre><code>  lazy val sparkDependencies = Seq(
    "org.apache.spark" %% "spark-hive" % sparkVersion,
    "org.apache.spark" %% "spark-core" % sparkVersion,
    "org.apache.spark" %% "spark-sql" % sparkVersion
  ).map(_ % "provided")
   .map(_.excludeAll(ExclusionRule(organization = "org.scala-lang")))
</code></pre>

<p>When I tried to run a class from the IDE I get this exception:</p>

<pre><code>java.lang.NoClassDefFoundError: org/apache/spark/sql/SparkSession
    at java.lang.Class.getDeclaredMethods0(Native Method)
    at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
    at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
    at java.lang.Class.getMethod0(Class.java:3018)
    at java.lang.Class.getMethod(Class.java:1784)
</code></pre>

<p>I followed the instruction here: 
<a href="https://github.com/sbt/sbt-assembly#-provided-configuration" rel="nofollow">https://github.com/sbt/sbt-assembly#-provided-configuration</a> and added the following line to my <code>build.sbt</code></p>

<pre><code>run in Compile &lt;&lt;= Defaults.runTask(fullClasspath in Compile, mainClass in(Compile, run), runner in(Compile, run))
</code></pre>

<p>This works when I call <code>sbt run</code> from the command line, but when I try to run it from InteliJ I still get the exception.</p>

<p>I though that I could use the <code>Project.inTask</code> method of <code>sbt</code> but I can not figure out how to do it. I would love to do a dumb simple <code>if-else</code> statement something like</p>

<pre><code>if(i am running assembly){
  Dependencies.dependenciesProvided 
}else{
  Dependencies.dependenciesAll
}
</code></pre>

<p>To put this in terms of <code>sbt</code>:</p>

<pre><code>lazy val `root` = project.in(file("."))
  .settings(common)
  .settings(inTask(assembly)(libraryDependencies ++= Dependencies.dependenciesProvided))
  .settings(inTask(???)(libraryDependencies ++ Dependencies.dependenciesAll))
</code></pre>

<p>Do you have any idea how to basically invert the scope <code>inTask(assembly)</code> and provide the dependencies in <em>all other cases other than assemly</em>?</p>

<p>Is it even possible?</p>

<p>Thanks</p>