Repository: scala-steward-org/scala-steward
Pull request #3538 (2025-01-12 16:09:08)

Run Mill 0.11 with `--disable-ticker` instead of `--ticker false`
Running Mill 0.11 with `--ticker=false` (which has been added in #3511) produces the following error:
```
Parsing exception Position 1:9, found "=false"
```
The `--ticker <bool>` option has been added to Mill in 0.12.0 if I'm reading [this commit](https://github.com/com-lihaoyi/mill/commit/0c44ffa3e1c197bef13df66baf452b1bf064433d) correctly. We therefore need to use `--disable-ticker` with Mill 0.11 and `--ticker false` with Mill >= 0.12.


Patch:
diff --git a/modules/core/src/main/scala/org/scalasteward/core/buildtool/mill/MillAlg.scala b/modules/core/src/main/scala/org/scalasteward/core/buildtool/mill/MillAlg.scala
index f5908025..e8bb2ebb 100644
--- a/modules/core/src/main/scala/org/scalasteward/core/buildtool/mill/MillAlg.scala
+++ b/modules/core/src/main/scala/org/scalasteward/core/buildtool/mill/MillAlg.scala
@@ -45,20 +45,23 @@ final class MillAlg[F[_]](defaultResolver: Resolver)(implicit
           .map(_.nonEmpty)
       )
 
-  private def runMill(buildRootDir: File) = {
-    val options =
-      List("--no-server", "--ticker=false", "--import", cliPluginCoordinate, "show", extractDeps)
-    val command = Nel("mill", options)
-    processAlg.execSandboxed(command, buildRootDir)
-  }
-  private def runMillUnder011(buildRootDir: File, millBuildVersion: Option[Version]) = {
-    val predef = buildRootDir / "scala-steward.sc"
-    val predefContent = content(millBuildVersion)
-    val command = Nel("mill", List("-i", "-p", predef.toString, "show", extractDeps))
-    fileAlg.createTemporarily(predef, predefContent).surround {
-      processAlg.execSandboxed(command, buildRootDir)
+  private def runMill(buildRootDir: File, millBuildVersion: Option[Version]): F[List[String]] =
+    millBuildVersion match {
+      case Some(v) if v >= Version("0.11") =>
+        val noTicker =
+          if (v >= Version("0.12")) List("--ticker", "false") else List("--disable-ticker")
+        val options =
+          "--no-server" :: noTicker ++ List("--import", cliPluginCoordinate, "show", extractDeps)
+        val command = Nel("mill", options)
+        processAlg.execSandboxed(command, buildRootDir)
+      case _ =>
+        val predef = buildRootDir / "scala-steward.sc"
+        val predefContent = content(millBuildVersion)
+        val command = Nel("mill", List("-i", "-p", predef.toString, "show", extractDeps))
+        fileAlg.createTemporarily(predef, predefContent).surround {
+          processAlg.execSandboxed(command, buildRootDir)
+        }
     }
-  }
 
   override def getDependencies(buildRoot: BuildRoot): F[List[Scope.Dependencies]] =
     for {
@@ -79,9 +82,7 @@ final class MillAlg[F[_]](defaultResolver: Resolver)(implicit
       millBuildVersion: Option[Version]
   ): F[List[Scope.Dependencies]] =
     for {
-      extracted <-
-        if (isMillVersionGreaterOrEqual011(millBuildVersion)) runMill(buildRootDir)
-        else runMillUnder011(buildRootDir, millBuildVersion)
+      extracted <- runMill(buildRootDir, millBuildVersion)
       parsed <- F.fromEither(
         parser.parseModules(extracted.dropWhile(!_.startsWith("{")).mkString("\n"))
       )
@@ -113,9 +114,6 @@ final class MillAlg[F[_]](defaultResolver: Resolver)(implicit
 }
 
 object MillAlg {
-  private[mill] def isMillVersionGreaterOrEqual011(millVersion: Option[Version]): Boolean =
-    millMinVersion(millVersion).flatMap(_.toIntOption).exists(_ >= 11)
-
   private[mill] def millMinVersion(millVersion: Option[Version]): Option[String] =
     millVersion.flatMap(_.value.trim.split("[.]", 3).take(2).lastOption)
 


Test patch:
diff --git a/modules/core/src/test/scala/org/scalasteward/core/buildtool/mill/MillAlgTest.scala b/modules/core/src/test/scala/org/scalasteward/core/buildtool/mill/MillAlgTest.scala
index 59145ad4..e2c64c02 100644
--- a/modules/core/src/test/scala/org/scalasteward/core/buildtool/mill/MillAlgTest.scala
+++ b/modules/core/src/test/scala/org/scalasteward/core/buildtool/mill/MillAlgTest.scala
@@ -31,7 +31,7 @@ class MillAlgTest extends FunSuite {
     assertEquals(state, expected)
   }
 
-  test("getDependencies, version >= 0.11") {
+  test("getDependencies, 0.11 <= version < 0.12") {
     val repo = Repo("lihaoyi", "fastparse")
     val buildRoot = BuildRoot(repo, ".")
     val repoDir = workspaceAlg.repoDir(repo).unsafeRunSync()
@@ -40,7 +40,7 @@ class MillAlgTest extends FunSuite {
       repoDir,
       "mill",
       "--no-server",
-      "--ticker=false",
+      "--disable-ticker",
       "--import",
       "ivy:org.scala-steward::scala-steward-mill-plugin::0.18.0",
       "show",
@@ -65,6 +65,37 @@ class MillAlgTest extends FunSuite {
     assertEquals(state, expected)
   }
 
+  test("getDependencies, 0.12 <= version") {
+    val repo = Repo("mill-alg", "test-3")
+    val buildRoot = BuildRoot(repo, ".")
+    val buildRootDir = workspaceAlg.buildRootDir(buildRoot).unsafeRunSync()
+    val millCmd = Cmd.execSandboxed(
+      buildRootDir,
+      "mill",
+      "--no-server",
+      "--ticker",
+      "false",
+      "--import",
+      "ivy:org.scala-steward::scala-steward-mill-plugin::0.18.0",
+      "show",
+      extractDeps
+    )
+    val initial = MockState.empty
+      .copy(commandOutputs = Map(millCmd -> Right(List("""{"modules":[]}"""))))
+      .addFiles(buildRootDir / ".mill-version" -> "0.12.5", buildRootDir / "build.sc" -> "")
+      .unsafeRunSync()
+    val state = millAlg.getDependencies(buildRoot).runS(initial).unsafeRunSync()
+    val expected = initial.copy(
+      trace = Vector(
+        Cmd("read", s"$buildRootDir/.mill-version"),
+        Cmd("read", s"$buildRootDir/.config/mill-version"),
+        millCmd,
+        Cmd("read", s"$buildRootDir/build.sc")
+      )
+    )
+    assertEquals(state, expected)
+  }
+
   test("predef-content") {
     assert(MillAlg.content(None).contains("_mill$MILL_BIN_PLATFORM"))
     assert(MillAlg.content(Some(Version("0.6.1"))).contains("_mill0.6"))