playframework - sbt: dynamic aggregation of subproject -
i invent system dynamically discover subprojects , aggregate them project automatically. or @ least configure somehow.
to this, i'm planning have either "modules" folder or optional configuration file containing paths modules.
in case i'd need loop through subfolders (or loop through list of paths configuration file), and aggregate each subproject. don't know how that.
currently i'm building in play framework build.sbt
file. need add loop this:
name := "mysite" version := "1.0" scalaversion := "2.11.1" lazy val root = (project in file(".")).enableplugins(playjava) //pseudocode: foreach( folder in 'modules' folder) { lazy val module = (project in file(folder)).enableplugins(playjava) root = root.dependson(module).aggregate(module) }
is there way this?
edit 3: code here working:
object mybuild extends build { name := "mysite" version := "1.0" scalaversion := "2.11.6" var m = new file("modules") var list = seq[projectreference]() var deps = seq[classpathdependency]() if (m.exists) { val subs = m.listfiles.filter ( _.isdirectory ).foreach { folder => var modulepath = new file("modules", folder.getname) println("found module " + modulepath) lazy val module:projectref = projectref(modulepath,folder.getname) lazy val dep:classpathdependency = classpathdependency(module, none) list = list :+ module deps = deps :+ dep } } lazy val root = project(id = "mysite", base = file(".")).enableplugins(playjava).aggregate(list:_*).dependson(deps:_*) }
edit 4:
see dale wijnand's solution below.
about error: runtimeexception: no project 'mymodule' in 'file:/users/me/mysite/modules/mymodule'
. fixed using solution https://stackoverflow.com/a/28820578
here:
project/build.scala
import sbt._ import sbt.keys._ import play.sbt._ import play.sbt.play.autoimport._ object build extends build { val commonsettings: seq[setting[_]] = seq( scalaversion := "2.11.7" ) lazy val modules = (file("modules") * directoryfilter).get.map { dir => project(dir.getname, dir).enableplugins(playjava).settings(commonsettings: _*) } lazy val root = (project in file(".")) .enableplugins(playjava) .settings( name := "mysite", version := "1.0" ) .settings(commonsettings: _*) .dependson(modules map (m => m: classpathdependency): _*) .aggregate(modules map (m => m: projectreference): _*) override lazy val projects = root +: modules }
note, make sure module directories don't contain build.sbt
files defining them projects cause confusing runtimeexception: no project 'x' in 'file:/x'
type exception, see can't use sbt 0.13.7 play subprojects
Comments
Post a Comment