-
Notifications
You must be signed in to change notification settings - Fork 2
/
WorkspacePlugin.scala
32 lines (26 loc) · 1.05 KB
/
WorkspacePlugin.scala
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
package xyz.driver.sbt
import java.nio.file.{Path, Paths}
import sbt._
/** Enables using both source and binary dependencies for the same module,
* for faster development cycles in multi-project workflows.
* Adapted from https://github.com/sbt/sbt-sriracha. */
object WorkspacePlugin extends AutoPlugin {
private var _workspace = sys.props.get("sbt.workspace").orElse(sys.env.get("SBT_WORKSPACE")).map { base =>
Paths.get(base)
}
def workspace: Option[Path] = synchronized(_workspace)
override val requires = plugins.JvmPlugin
override val trigger = allRequirements
object autoImport {
implicit class WorkspaceProject(project: Project) {
def dependsOn(binary: ModuleID, projectName: String, directory: Option[String] = None): Project =
WorkspacePlugin.workspace match {
case Some(base) =>
project.dependsOn(
ProjectRef(base.resolve(directory.getOrElse(projectName)).toUri, projectName)
)
case None => project.settings(Keys.libraryDependencies += binary)
}
}
}
}