aboutsummaryrefslogtreecommitdiff
path: root/plugin/src/main/scala/ch/jodersky/sbt/jni/plugins/RunDependencyFixPlugin.scala
blob: 3c4f92c75bee4d1cf02fa7452ef86df985e2124d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package ch.jodersky.sbt.jni.plugins

import sbt._
import sbt.Keys._
import java.io.File

/** Adds the extension method `dependsOnRun` to projects, to work around an sbt
  * bug. */
object RunDependencyFixPlugin extends AutoPlugin {

  override def requires = plugins.CorePlugin
  override def trigger = allRequirements

  object autoImport {

    val runClasspath = taskKey[Seq[sbt.internal.util.Attributed[File]]]("Classpath used in run task")

    def dependsOnRunSettings(project: Project) = Seq(
      runClasspath in Compile ++= (runClasspath in Compile in project).value,
      run := {
        Defaults.runTask(
          runClasspath in Compile,
          mainClass in Compile in run,
          runner in run
        ).evaluated
      }
    )

    implicit class RichProject(project: Project) {
      @deprecated("Workaround for https://github.com/sbt/sbt/issues/3425. " +
        "Use `dependsOn(<project> % Runtime)` when fixed.", "1.3.0")
      def dependsOnRun(other: Project) = {
        project.settings(dependsOnRunSettings(other): _*)
      }
    }

  }
  import autoImport._

  override def projectSettings = Seq(
    runClasspath in Compile := (fullClasspath in Compile).value
  )

}