From 146d58bc5d98da1d142758f974d4d5de6f5948bf Mon Sep 17 00:00:00 2001 From: Guillaume Martres Date: Sat, 25 Aug 2018 18:28:59 +0900 Subject: Fix incremental compilation when a Scala project depends on a Java project (#414) * Upgrade ammonite to 1.1.2-30-53edc31 This is mainly to get https://github.com/lihaoyi/Ammonite/pull/851 which should reduce the amount of unnecessary work done by incremental compilation in the Mill build. This requires some code changes since this means we now depend on a more recent version of coursier, as a side-effect this means that we do not depend on scalaz anymore. Also use the same ammonite version in the Mill build and in ScalaModule#ammoniteReplClasspath. Also remove an incorrect dependency in the caffeine integration test. This was always wrong but did not start failing until this commit, probably due to dependencies appearing in a different order on the classpath. * Rename ScalaWorker to ZincWorker Starting with the next commit, it will be used in Java-only projects too, so the name is misleading. * Upgrade to Zinc 1.2.1 * Fix incremental compilation when a Scala project depends on a Java project Before this commit, JavaModule#compile simply called javac unconditionally, thus generating new classfiles every time. But if a Scala project depends on a Java project, this will throw off the incremental compilation algorithm which will unnecessarily recompile files. To avoid this we now use Zinc to compile Java projects too (as a bonus this means that Java compilation becomes incremental). This required some refactoring in ZincWorkerImpl to be able to compile stuff without having to pass Scala-specific options. The issue solved by this commit could be reproduced by running in the Mill repository: $ mill main.compile $ mill -i @ main.compile() and observing that before this commit, the `main.compile()` call ended up recompiling code. --- main/src/mill/modules/Jvm.scala | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) (limited to 'main/src') diff --git a/main/src/mill/modules/Jvm.scala b/main/src/mill/modules/Jvm.scala index 3a6dcb9f..96992d20 100644 --- a/main/src/mill/modules/Jvm.scala +++ b/main/src/mill/modules/Jvm.scala @@ -10,6 +10,7 @@ import java.util.jar.{JarEntry, JarFile, JarOutputStream} import ammonite.ops._ import coursier.{Cache, Dependency, Fetch, Repository, Resolution} +import coursier.util.{Gather, Task} import geny.Generator import mill.main.client.InputPumper import mill.eval.{PathRef, Result} @@ -383,7 +384,7 @@ object Jvm { /** * Resolve dependencies using Coursier. * - * We do not bother breaking this out into the separate ScalaWorker classpath, + * We do not bother breaking this out into the separate ZincWorkerApi classpath, * because Coursier is already bundled with mill/Ammonite to support the * `import $ivy` syntax. */ @@ -413,17 +414,19 @@ object Jvm { def load(artifacts: Seq[coursier.Artifact]) = { val logger = None - val loadedArtifacts = scalaz.concurrent.Task.gatherUnordered( + + import scala.concurrent.ExecutionContext.Implicits.global + val loadedArtifacts = Gather[Task].gather( for (a <- artifacts) - yield coursier.Cache.file(a, logger = logger).run + yield coursier.Cache.file[Task](a, logger = logger).run .map(a.isOptional -> _) - ).unsafePerformSync + ).unsafeRun val errors = loadedArtifacts.collect { - case (false, scalaz.-\/(x)) => x - case (true, scalaz.-\/(x)) if !x.notFound => x + case (false, Left(x)) => x + case (true, Left(x)) if !x.notFound => x } - val successes = loadedArtifacts.collect { case (_, scalaz.\/-(x)) => x } + val successes = loadedArtifacts.collect { case (_, Right(x)) => x } (errors, successes) } @@ -459,8 +462,10 @@ object Jvm { mapDependencies = mapDependencies ) - val fetch = Fetch.from(repositories, Cache.fetch()) - val resolution = start.process.run(fetch).unsafePerformSync + val fetch = Fetch.from(repositories, Cache.fetch[Task]()) + + import scala.concurrent.ExecutionContext.Implicits.global + val resolution = start.process.run(fetch).unsafeRun() (deps.toSeq, resolution) } } -- cgit v1.2.3