How setup sbt for parallel package into jars? -
i have sbt project several modules need packaged jar archives. see in logs sbt packages each project jar sequentially:
[info] packaging c:path\target\scala-2.11\projectfirst ... [info] packaging c:path\target\scala-2.11\projectsecond ... [info] packaging c:path\target\scala-2.11\projectthrird ...
projects not depend of each other , can packaged in parallel. there possibility setup sbt package projects in parallel?
in sbt documentation can find following sentence:
by default, sbt executes tasks in parallel.
i prepared experiment check this. created project 4 subprojects. code:
main build.sbt:
lazy val sub1 = project lazy val sub2 = project lazy val sub3 = project lazy val sub4 = project keys.`package` in compile <<= (keys.`package` in compile).dependson(def.task { })
sub1/build.sbt
keys.`package` in compile <<= (keys.`package` in compile).dependson(def.task { for( <- 1 2){ thread.sleep(1000) println( "subproject 1: " + ); } })
in sub2, sub3 , sub4 build.sbt identical in sub1. changed number of iterations , printed number. received following output:
> package subproject 4: 1 subproject 1: 1 subproject 4: 2 subproject 1: 2 subproject 4: 3 subproject 3: 1 subproject 4: 4 subproject 3: 2 subproject 4: 5 subproject 3: 3 subproject 4: 6 subproject 3: 4 subproject 4: 7 subproject 2: 1 subproject 4: 8 subproject 2: 2 subproject 4: 9 subproject 2: 3 [info] updating {file:/d:/sbt/abc/}sub1... [info] resolving org.scala-lang#scala-library;2.10.4 ... [info] resolving org.scala-lang#scala-compiler;2.10.4 ... subproject 4: 10 [info] resolving org.scala-lang#scala-reflect;2.10.4 ... [info] resolving org.scala-lang#jline;2.10.4 ... [info] resolving org.fusesource.jansi#jansi;1.4 ... [info] done updating. [info] updating {file:/d:/sbt/abc/}abc... [info] resolving org.scala-lang#scala-library;2.10.4 ... [info] resolving org.scala-lang#scala-compiler;2.10.4 ... [info] resolving org.scala-lang#scala-reflect;2.10.4 ... [info] resolving org.scala-lang#jline;2.10.4 ... [info] resolving org.fusesource.jansi#jansi;1.4 ... [info] done updating. [info] updating {file:/d:/sbt/abc/}sub3... [info] resolving org.scala-lang#scala-library;2.10.4 ... [info] resolving org.scala-lang#scala-compiler;2.10.4 ... [info] resolving org.scala-lang#scala-reflect;2.10.4 ... [info] resolving org.scala-lang#jline;2.10.4 ... [info] resolving org.fusesource.jansi#jansi;1.4 ... [info] done updating. [info] updating {file:/d:/sbt/abc/}sub2... [info] resolving org.scala-lang#scala-library;2.10.4 ... [info] resolving org.scala-lang#scala-compiler;2.10.4 ... [info] resolving org.scala-lang#scala-reflect;2.10.4 ... [info] resolving org.scala-lang#jline;2.10.4 ... [info] resolving org.fusesource.jansi#jansi;1.4 ... subproject 4: 11 [info] done updating. [info] packaging d:\sbt\abc\sub1\target\scala-2.10\sub1_2.10-0.1-snapshot.jar ... [info] done packaging. [info] packaging d:\sbt\abc\target\scala-2.10\abc_2.10-0.1-snapshot.jar ... [info] done packaging. [info] packaging d:\sbt\abc\sub3\target\scala-2.10\sub3_2.10-0.1-snapshot.jar ... [info] done packaging. [info] packaging d:\sbt\abc\sub2\target\scala-2.10\sub2_2.10-0.1-snapshot.jar ... [info] done packaging. subproject 4: 12 subproject 4: 13 subproject 4: 14 subproject 4: 15 subproject 4: 16 subproject 4: 17 subproject 4: 18 subproject 4: 19 subproject 4: 20 [info] updating {file:/d:/sbt/abc/}sub4... [info] resolving org.scala-lang#scala-library;2.10.4 ... [info] resolving org.scala-lang#scala-compiler;2.10.4 ... [info] resolving org.scala-lang#scala-reflect;2.10.4 ... [info] resolving org.scala-lang#jline;2.10.4 ... [info] resolving org.fusesource.jansi#jansi;1.4 ... [info] done updating. [info] packaging d:\sbt\abc\sub4\target\scala-2.10\sub4_2.10-0.1-snapshot.jar ... [info] done packaging.
so there 4 subprojects. in every subproject 'package' task depends on created task (which prints , sleeps in loop). when execute 'package' command then task executed wach sub-project. each 1 dependent task called. can see in output these dependent tasks run pallalelly 2 @ time. coresponds following sentence doc:
(although never exposed setting, maximum number of tasks running @ given time internally configurable well.)
following 3 lines output:
[info] resolving org.scala-lang#scala-compiler;2.10.4 ... subproject 4: 10 [info] resolving org.scala-lang#scala-reflect;2.10.4 ...
provide proof packaging task 1 subproject runs parallelly dependent task other subproject.
Comments
Post a Comment