summaryrefslogtreecommitdiff
path: root/scalaplugin
diff options
context:
space:
mode:
authorLi Haoyi <haoyi.sg@gmail.com>2017-11-11 20:18:01 -0800
committerLi Haoyi <haoyi.sg@gmail.com>2017-11-11 20:18:01 -0800
commit37fd5e9de133dc157cdaa6d432700b93324680fe (patch)
treeb30b279b32c48813cce30507473e4fab65c2fe50 /scalaplugin
parent21325c4dd9e52d6ae6f6b1a8ce606962922100b1 (diff)
downloadmill-37fd5e9de133dc157cdaa6d432700b93324680fe.tar.gz
mill-37fd5e9de133dc157cdaa6d432700b93324680fe.tar.bz2
mill-37fd5e9de133dc157cdaa6d432700b93324680fe.zip
- Smoothed out syntax for defining ivy dependencies
- Made `build.sc` file directly runnable using Ammonite, without any wrapper
Diffstat (limited to 'scalaplugin')
-rw-r--r--scalaplugin/src/main/scala/mill/scalaplugin/Subproject.scala64
-rw-r--r--scalaplugin/src/test/scala/mill/scalaplugin/MetacircularTests.scala16
2 files changed, 49 insertions, 31 deletions
diff --git a/scalaplugin/src/main/scala/mill/scalaplugin/Subproject.scala b/scalaplugin/src/main/scala/mill/scalaplugin/Subproject.scala
index 0408833a..2dcbbe04 100644
--- a/scalaplugin/src/main/scala/mill/scalaplugin/Subproject.scala
+++ b/scalaplugin/src/main/scala/mill/scalaplugin/Subproject.scala
@@ -116,11 +116,11 @@ object Subproject{
def resolveDependencies(repositories: Seq[Repository],
scalaVersion: String,
scalaBinaryVersion: String,
- deps: Seq[ScalaDep]): Seq[PathRef] = {
+ deps: Seq[Dep]): Seq[PathRef] = {
val flattened = deps.map{
- case ScalaDep.Java(dep) => dep
- case ScalaDep.Scala(dep) => dep.copy(module = dep.module.copy(name = dep.module.name + "_" + scalaBinaryVersion))
- case ScalaDep.Point(dep) => dep.copy(module = dep.module.copy(name = dep.module.name + "_" + scalaVersion))
+ case Dep.Java(dep) => dep
+ case Dep.Scala(dep) => dep.copy(module = dep.module.copy(name = dep.module.name + "_" + scalaBinaryVersion))
+ case Dep.Point(dep) => dep.copy(module = dep.module.copy(name = dep.module.name + "_" + scalaVersion))
}.toSet
val start = Resolution(flattened)
@@ -133,22 +133,40 @@ object Subproject{
localArtifacts.map(p => PathRef(Path(p)))
}
- def scalaCompilerIvyDeps(scalaVersion: String) = Seq[ScalaDep](
- Dependency(Module("org.scala-lang", "scala-compiler"), scalaVersion),
- ScalaDep.Scala(Dependency(Module("org.scala-sbt", s"compiler-bridge"), "1.0.3"))
+ def scalaCompilerIvyDeps(scalaVersion: String) = Seq(
+ Dep.Java("org.scala-lang", "scala-compiler", scalaVersion),
+ Dep("org.scala-sbt", s"compiler-bridge", "1.0.3")
)
- def scalaRuntimeIvyDeps(scalaVersion: String) = Seq[ScalaDep](
- Dependency(Module("org.scala-lang", "scala-library"), scalaVersion)
+ def scalaRuntimeIvyDeps(scalaVersion: String) = Seq[Dep](
+ Dep.Java("org.scala-lang", "scala-library", scalaVersion)
)
- sealed trait ScalaDep
- object ScalaDep{
- case class Java(dep: coursier.Dependency) extends ScalaDep
- implicit def default(dep: coursier.Dependency): ScalaDep = new Java(dep)
+ sealed trait Dep
+ object Dep{
+ def apply(org: String, name: String, version: String): Dep = {
+ this(coursier.Dependency(coursier.Module(org, name), version))
+ }
+ case class Java(dep: coursier.Dependency) extends Dep
+ object Java{
+ def apply(org: String, name: String, version: String): Dep = {
+ Java(coursier.Dependency(coursier.Module(org, name), version))
+ }
+ }
+ implicit def default(dep: coursier.Dependency): Dep = new Java(dep)
def apply(dep: coursier.Dependency) = Scala(dep)
- case class Scala(dep: coursier.Dependency) extends ScalaDep
- case class Point(dep: coursier.Dependency) extends ScalaDep
- implicit def formatter: Format[ScalaDep] = new Format[ScalaDep]{
- def writes(o: ScalaDep) = o match{
+ case class Scala(dep: coursier.Dependency) extends Dep
+ object Scala{
+ def apply(org: String, name: String, version: String): Dep = {
+ Scala(coursier.Dependency(coursier.Module(org, name), version))
+ }
+ }
+ case class Point(dep: coursier.Dependency) extends Dep
+ object Point{
+ def apply(org: String, name: String, version: String): Dep = {
+ Point(coursier.Dependency(coursier.Module(org, name), version))
+ }
+ }
+ implicit def formatter: Format[Dep] = new Format[Dep]{
+ def writes(o: Dep) = o match{
case Java(dep) => Json.obj("Java" -> Json.toJson(dep))
case Scala(dep) => Json.obj("Scala" -> Json.toJson(dep))
case Point(dep) => Json.obj("PointScala" -> Json.toJson(dep))
@@ -157,9 +175,9 @@ object Subproject{
def reads(json: JsValue) = json match{
case obj: JsObject =>
obj.fields match{
- case Seq(("Java", dep)) => Json.fromJson[coursier.Dependency](dep).map(Java)
- case Seq(("Scala", dep)) => Json.fromJson[coursier.Dependency](dep).map(Scala)
- case Seq(("PointScala", dep)) => Json.fromJson[coursier.Dependency](dep).map(Point)
+ case Seq(("Java", dep)) => Json.fromJson[coursier.Dependency](dep).map(Java(_))
+ case Seq(("Scala", dep)) => Json.fromJson[coursier.Dependency](dep).map(Scala(_))
+ case Seq(("PointScala", dep)) => Json.fromJson[coursier.Dependency](dep).map(Point(_))
case _ => JsError("Invalid JSON object to parse ScalaDep")
}
@@ -175,9 +193,9 @@ trait Subproject extends Cacher{
def scalaVersion: T[String]
def scalaBinaryVersion = T{ scalaVersion().split('.').dropRight(1).mkString(".") }
- def ivyDeps = T{ Seq[ScalaDep]() }
- def compileIvyDeps = T{ Seq[ScalaDep]() }
- def runIvyDeps = T{ Seq[ScalaDep]() }
+ def ivyDeps = T{ Seq[Dep]() }
+ def compileIvyDeps = T{ Seq[Dep]() }
+ def runIvyDeps = T{ Seq[Dep]() }
def basePath: T[Path]
val repositories: Seq[Repository] = Seq(
diff --git a/scalaplugin/src/test/scala/mill/scalaplugin/MetacircularTests.scala b/scalaplugin/src/test/scala/mill/scalaplugin/MetacircularTests.scala
index 21640e6b..8159b8ce 100644
--- a/scalaplugin/src/test/scala/mill/scalaplugin/MetacircularTests.scala
+++ b/scalaplugin/src/test/scala/mill/scalaplugin/MetacircularTests.scala
@@ -5,7 +5,7 @@ import ammonite.ops.pwd
import coursier.{Dependency => Dep, Module => Mod}
import mill.discover.Discovered
import mill.eval.{Evaluator, PathRef}
-import mill.scalaplugin.Subproject.ScalaDep
+import mill.scalaplugin.Subproject.Dep
import mill.util.OSet
import utest._
@@ -13,18 +13,18 @@ object MetacircularTests extends TestSuite{
object Core extends Subproject {
def scalaVersion = T{ "2.12.4" }
override def compileIvyDeps = T{
- super.compileIvyDeps() ++ Seq[ScalaDep](
+ super.compileIvyDeps() ++ Seq[Dep](
Dep(Mod("org.scala-lang", "scala-reflect"), scalaVersion(), configuration = "provided")
)
}
override def ivyDeps = T{
- super.ivyDeps() ++ Seq[ScalaDep](
- ScalaDep(Dep(Mod("com.lihaoyi", "sourcecode"), "0.1.4")),
- ScalaDep(Dep(Mod("com.lihaoyi", "pprint"), "0.5.3")),
- ScalaDep.Point(Dep(Mod("com.lihaoyi", "ammonite"), "1.0.3")),
- ScalaDep(Dep(Mod("com.typesafe.play", "play-json"), "2.6.6")),
- ScalaDep(Dep(Mod("org.scala-sbt", "zinc"), "1.0.3"))
+ super.ivyDeps() ++ Seq[Dep](
+ Dep(Dep(Mod("com.lihaoyi", "sourcecode"), "0.1.4")),
+ Dep(Dep(Mod("com.lihaoyi", "pprint"), "0.5.3")),
+ Dep.Point(Dep(Mod("com.lihaoyi", "ammonite"), "1.0.3")),
+ Dep(Dep(Mod("com.typesafe.play", "play-json"), "2.6.6")),
+ Dep(Dep(Mod("org.scala-sbt", "zinc"), "1.0.3"))
)
}