Skip to content

Instantly share code, notes, and snippets.

@pomadchin
Created November 12, 2015 11:53
Show Gist options
  • Save pomadchin/85d38921fc7bd863d67f to your computer and use it in GitHub Desktop.
Save pomadchin/85d38921fc7bd863d67f to your computer and use it in GitHub Desktop.
Build util
// http://scastie.org/13093
/***
sbtPlugin := true
*/
import sbt._
import Keys._
object BuildUtil {
private val localLibs = scala.util.Try(IO.read(file("local-libs.txt"))).map(_.split('\n').map(_.trim).toSet).getOrElse(Set())
implicit class ProjectExt(p: Project) {
/**
* if artifactId is in local-libs.txt then add project at a sibling directory with that name as a dependency, otherwise add that artifact as a regular dependency
*/
def addLib(artifactId: String, version: String) = {
val org = "com.com"
if (localLibs(artifactId)) {
val ref = ProjectRef(file("..") / artifactId, artifactId)
val exclude = allDependencies ~= (_.map(_.exclude(org, artifactId)).filterNot(m => m.organization == org && m.name == artifactId))
p.dependsOn(ref).aggregate(ref).settings(exclude)
}
else {
p.settings(libraryDependencies += org %% artifactId % version)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment