diff options
author | Jean Helou <jhe@codamens.fr> | 2019-02-25 17:00:16 +0100 |
---|---|---|
committer | Tobias Roeser <le.petit.fou@web.de> | 2019-03-11 07:41:03 +0100 |
commit | 2cac5a37351f4ec13c5b29d8bd292a7153762e87 (patch) | |
tree | 9650708f75f91119d4092de63e3343d1f02d6cb4 | |
parent | dca05d702bb53b562570f70c30d7767e81c29a76 (diff) | |
download | mill-2cac5a37351f4ec13c5b29d8bd292a7153762e87.tar.gz mill-2cac5a37351f4ec13c5b29d8bd292a7153762e87.tar.bz2 mill-2cac5a37351f4ec13c5b29d8bd292a7153762e87.zip |
Provides additionnal dependency keys for easier configuration
-rw-r--r-- | contrib/playlib/src/mill/playlib/Dependencies.scala | 19 | ||||
-rw-r--r-- | contrib/playlib/src/mill/playlib/Server.scala | 14 | ||||
-rw-r--r-- | contrib/playlib/src/mill/playlib/Version.scala | 7 | ||||
-rw-r--r-- | contrib/playlib/test/src/mill/playlib/PlayModuleTests.scala | 19 | ||||
-rw-r--r-- | docs/pages/9 - Contrib Modules.md | 35 |
5 files changed, 82 insertions, 12 deletions
diff --git a/contrib/playlib/src/mill/playlib/Dependencies.scala b/contrib/playlib/src/mill/playlib/Dependencies.scala index 2583ffbf..65a5f455 100644 --- a/contrib/playlib/src/mill/playlib/Dependencies.scala +++ b/contrib/playlib/src/mill/playlib/Dependencies.scala @@ -2,14 +2,23 @@ package mill package playlib import mill.scalalib._ -import mill.scalalib.api._ private [playlib] trait Dependencies extends ScalaModule with Version{ + def core = T { component("play") } + def guice = T { component("play-guice") } + def server = T { component("play-server") } + def logback = T { component("play-logback") } + def evolutions = T { component("play-jdbc-evolutions") } + def jdbc = T { component("play-jdbc") } + def filters = T { component("filters-helpers") } + def ws = T { component("play-ahc-ws") } + def caffeine = T { component("play-caffeine-cache") } + override def ivyDeps = T{ super.ivyDeps() ++ Agg( - ivy"com.typesafe.play::play:${playVersion()}", - ivy"com.typesafe.play::play-guice:${playVersion()}", - ivy"com.typesafe.play::play-server:${playVersion()}", - ivy"com.typesafe.play::play-logback:${playVersion()}" + core(), + guice(), + server(), + logback() )} } diff --git a/contrib/playlib/src/mill/playlib/Server.scala b/contrib/playlib/src/mill/playlib/Server.scala index f41c41d7..0b7b086a 100644 --- a/contrib/playlib/src/mill/playlib/Server.scala +++ b/contrib/playlib/src/mill/playlib/Server.scala @@ -4,17 +4,19 @@ package playlib import mill.scalalib._ private[playlib] trait Server extends ScalaModule with Version { - def playServerProvider = T { - ivy"com.typesafe.play::play-akka-http-server:${playVersion()}" - } + + def nettyServer = T { component("play-netty-server") } + + def akkaHttpServer = T { component("play-akka-http-server") } + + def playServerProvider = T { akkaHttpServer() } + override def runIvyDeps = T { super.runIvyDeps() ++ Agg(playServerProvider()) } - override def mainClass = T { - Some("play.core.server.ProdServerStart") - } + override def mainClass = T { Some("play.core.server.ProdServerStart") } } diff --git a/contrib/playlib/src/mill/playlib/Version.scala b/contrib/playlib/src/mill/playlib/Version.scala index 77e57886..ae441a8a 100644 --- a/contrib/playlib/src/mill/playlib/Version.scala +++ b/contrib/playlib/src/mill/playlib/Version.scala @@ -1,6 +1,9 @@ package mill package playlib +import mill.define.{Target, Task} +import mill.scalalib._ + private[playlib] trait Version extends Module{ def playVersion: T[String] @@ -8,4 +11,8 @@ private[playlib] trait Version extends Module{ private[playlib] def playMinorVersion: T[String] = T { playVersion().split("\\.").take(2).mkString("", ".", ".0") } + + private[playlib] def component(id: String): Task[Dep] = T.task { + ivy"com.typesafe.play::$id::${playVersion()}" + } } diff --git a/contrib/playlib/test/src/mill/playlib/PlayModuleTests.scala b/contrib/playlib/test/src/mill/playlib/PlayModuleTests.scala index a04df0bc..398634ce 100644 --- a/contrib/playlib/test/src/mill/playlib/PlayModuleTests.scala +++ b/contrib/playlib/test/src/mill/playlib/PlayModuleTests.scala @@ -14,7 +14,7 @@ object PlayModuleTests extends TestSuite { override def twirlVersion = T{"1.4.0"} override def scalaVersion = T{"2.12.8"} object test extends PlayTests - + override def ivyDeps = T { super.ivyDeps() ++ Agg(ws())} } } @@ -59,6 +59,23 @@ object PlayModuleTests extends TestSuite { ) } } + 'dependencies - { + 'fromBuild - workspaceTest(playmulti) { eval => + val Right((deps, evalCount)) = eval.apply(playmulti.core.ivyDeps) + val expectedModules = Seq[String]( + "play", + "play-guice", + "play-server", + "play-logback", + "play-ahc-ws" + ) + val outputModules = deps.map(_.dep.module.name) + assert( + outputModules.forall(expectedModules.contains), + evalCount > 0 + ) + } + } 'compile - workspaceTest(playmulti) { eval => val eitherResult = eval.apply(playmulti.core.compile) val Right((result, evalCount)) = eitherResult diff --git a/docs/pages/9 - Contrib Modules.md b/docs/pages/9 - Contrib Modules.md index 418978a7..44883959 100644 --- a/docs/pages/9 - Contrib Modules.md +++ b/docs/pages/9 - Contrib Modules.md @@ -275,6 +275,7 @@ There's an [example project](https://github.com/lihaoyi/cask/tree/master/example This module adds basic Play Framework support to mill: - configures mill for Play default directory layout, - integrates the Play routes compiler, +- provides helpers for commonly used framework libraries, - optionally: integrates the Twirl template engine, - optionally: configures mill for single module play applications. @@ -390,6 +391,40 @@ The Play modules themselves don't have specific configuration options at this po module configuration options](#router-configuration-options) and the [Twirl module configuration options](#twirl-configuration-options) are applicable. +#### Additional play libraries + +The following helpers are available to provide additional Play Framework dependencies: +- `core()` - added by default , +- `guice()` - added by default, +- `server()` - added by default, +- `logback()` - added by default, +- `evolutions()` - optional, +- `jdbc()` - optional, +- `filters()` - optional, +- `ws()` - optional, +- `caffeine()` - optional. + +If you want to add an optional library using the helper you can do so by overriding `ivyDeps` +like in the following example build: + +```scala +// build.sc +import mill._ +// You have to replace VERSION +import $ivy.`com.lihaoyi::mill-contrib-playlib:VERSION`, mill.playlib._ + + +object core extends PlayApiModule { + //config + override def scalaVersion= T{"2.12.8"} + override def playVersion= T{"2.7.0"} + + object test extends PlayTests + + override def ivyDeps = T{ super.ivyDeps() ++ Agg(ws(), filters()) } +} +``` + #### Commands equivalence Mill commands are targets on a named build. For example if your build is called `core`: |