Repository: scala-steward-org/scala-steward
Pull request #2478 (2022-01-24 12:52:50)

Update Coursier to 2.1.0-M2-19-g5a34ba7c1
This includes https://github.com/coursier/coursier/pull/2332.


Patch:
diff --git a/build.sbt b/build.sbt
index c46340ad..063bdabd 100644
--- a/build.sbt
+++ b/build.sbt
@@ -60,6 +60,10 @@ ThisBuild / githubWorkflowBuild :=
     )
   )
 
+/// global build settings
+
+ThisBuild / evictionErrorLevel := Level.Info
+
 /// projects
 
 lazy val root = project
@@ -123,20 +127,14 @@ lazy val core = myCrossProject("core")
     ),
     assembly / test := {},
     assembly / assemblyMergeStrategy := {
-      val nativeSuffix = "\\.(?:dll|jnilib|so)$".r
-
-      {
-        case PathList(ps @ _*) if nativeSuffix.findFirstMatchIn(ps.last).isDefined =>
-          MergeStrategy.first
-        case PathList("org", "fusesource", _*) =>
-          // (core / assembly) deduplicate: different file contents found in the following:
-          // https/repo1.maven.org/maven2/jline/jline/2.14.6/jline-2.14.6.jar:org/fusesource/hawtjni/runtime/Callback.class
-          // https/repo1.maven.org/maven2/org/fusesource/jansi/jansi/1.18/jansi-1.18.jar:org/fusesource/hawtjni/runtime/Callback.class
-          MergeStrategy.first
-        case otherwise =>
-          val defaultStrategy = (assembly / assemblyMergeStrategy).value
-          defaultStrategy(otherwise)
-      }
+      case PathList("META-INF", "versions", "9", "module-info.class") =>
+        // (core / assembly) deduplicate: different file contents found in the following:
+        // https/repo1.maven.org/maven2/org/jetbrains/kotlin/kotlin-stdlib/1.4.20/kotlin-stdlib-1.4.20.jar:META-INF/versions/9/module-info.class
+        // https/repo1.maven.org/maven2/org/tukaani/xz/1.9/xz-1.9.jar:META-INF/versions/9/module-info.class
+        MergeStrategy.first
+      case otherwise =>
+        val defaultStrategy = (assembly / assemblyMergeStrategy).value
+        defaultStrategy(otherwise)
     },
     buildInfoKeys := Seq[BuildInfoKey](
       organization,
diff --git a/modules/core/src/main/scala/org/scalasteward/core/buildtool/sbt/SbtAlg.scala b/modules/core/src/main/scala/org/scalasteward/core/buildtool/sbt/SbtAlg.scala
index f8dae952..2cb68489 100644
--- a/modules/core/src/main/scala/org/scalasteward/core/buildtool/sbt/SbtAlg.scala
+++ b/modules/core/src/main/scala/org/scalasteward/core/buildtool/sbt/SbtAlg.scala
@@ -24,6 +24,7 @@ import org.scalasteward.core.application.Config
 import org.scalasteward.core.buildtool.BuildToolAlg
 import org.scalasteward.core.buildtool.sbt.command._
 import org.scalasteward.core.buildtool.sbt.data.SbtVersion
+import org.scalasteward.core.coursier.VersionsCache
 import org.scalasteward.core.data.{Dependency, Scope}
 import org.scalasteward.core.edit.scalafix.{ScalafixCli, ScalafixMigration}
 import org.scalasteward.core.io.{FileAlg, FileData, ProcessAlg, WorkspaceAlg}
@@ -37,6 +38,7 @@ final class SbtAlg[F[_]](config: Config)(implicit
     processAlg: ProcessAlg[F],
     scalafixCli: ScalafixCli[F],
     workspaceAlg: WorkspaceAlg[F],
+    versionsCache: VersionsCache[F],
     F: Concurrent[F]
 ) extends BuildToolAlg[F] {
   private def getSbtDependency(buildRoot: BuildRoot): F[Option[Dependency]] =
@@ -81,18 +83,27 @@ final class SbtAlg[F[_]](config: Config)(implicit
     }
 
   private def runSourcesMigration(buildRoot: BuildRoot, migration: ScalafixMigration): F[Unit] =
-    addGlobalPluginTemporarily(scalaStewardScalafixSbt).surround {
-      workspaceAlg.buildRootDir(buildRoot).flatMap { buildRootDir =>
-        val withScalacOptions =
-          migration.scalacOptions.fold(Resource.unit[F]) { opts =>
-            val file = scalaStewardScalafixOptions(opts.toList)
-            fileAlg.createTemporarily(buildRootDir / file.name, file.content)
-          }
-        val scalafixCmds = migration.rewriteRules.map(rule => s"$scalafixAll $rule").toList
-        withScalacOptions.surround(sbt(Nel(scalafixEnable, scalafixCmds), buildRootDir).void)
+    sbtScalaFixPluginVersion.foreachF { pluginVersion =>
+      addGlobalPluginTemporarily(scalaStewardScalafixSbt(pluginVersion)).surround {
+        workspaceAlg.buildRootDir(buildRoot).flatMap { buildRootDir =>
+          val withScalacOptions =
+            migration.scalacOptions.fold(Resource.unit[F]) { opts =>
+              val file = scalaStewardScalafixOptions(opts.toList)
+              fileAlg.createTemporarily(buildRootDir / file.name, file.content)
+            }
+          val scalafixCmds = migration.rewriteRules.map(rule => s"$scalafixAll $rule").toList
+          withScalacOptions.surround(sbt(Nel(scalafixEnable, scalafixCmds), buildRootDir).void)
+        }
       }
     }
 
+  private def sbtScalaFixPluginVersion: OptionT[F, String] =
+    OptionT(
+      versionsCache
+        .getVersions(Scope(sbtScalaFixDependency, List(config.defaultResolver)), None)
+        .map(_.lastOption.map(_.value))
+    )
+
   private def runBuildMigration(buildRoot: BuildRoot, migration: ScalafixMigration): F[Unit] =
     for {
       buildRootDir <- workspaceAlg.buildRootDir(buildRoot)
diff --git a/modules/core/src/main/scala/org/scalasteward/core/buildtool/sbt/package.scala b/modules/core/src/main/scala/org/scalasteward/core/buildtool/sbt/package.scala
index 07edb542..116d3def 100644
--- a/modules/core/src/main/scala/org/scalasteward/core/buildtool/sbt/package.scala
+++ b/modules/core/src/main/scala/org/scalasteward/core/buildtool/sbt/package.scala
@@ -18,7 +18,7 @@ package org.scalasteward.core.buildtool
 
 import cats.Functor
 import cats.syntax.all._
-import org.scalasteward.core.buildtool.sbt.data.SbtVersion
+import org.scalasteward.core.buildtool.sbt.data.{SbtVersion, ScalaVersion}
 import org.scalasteward.core.data.{ArtifactId, Dependency, GroupId, Version}
 import org.scalasteward.core.io.{FileAlg, FileData}
 
@@ -35,10 +35,19 @@ package object sbt {
       Dependency(sbtGroupId, sbtArtifactId, sbtVersion.value)
     }
 
-  val scalaStewardScalafixSbt: FileData =
+  val sbtScalaFixDependency: Dependency =
+    Dependency(
+      GroupId("ch.epfl.scala"),
+      ArtifactId("sbt-scalafix"),
+      "",
+      Some(SbtVersion("1.0")),
+      Some(ScalaVersion("2.12"))
+    )
+
+  def scalaStewardScalafixSbt(version: String): FileData =
     FileData(
       "scala-steward-scalafix.sbt",
-      """addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.9.34")"""
+      s"""addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "$version")"""
     )
 
   def scalaStewardScalafixOptions(scalacOptions: List[String]): FileData = {
diff --git a/project/Dependencies.scala b/project/Dependencies.scala
index bcb36b8d..a4aed010 100644
--- a/project/Dependencies.scala
+++ b/project/Dependencies.scala
@@ -16,7 +16,7 @@ object Dependencies {
   val circeParser = "io.circe" %% "circe-parser" % circeGeneric.revision
   val circeRefined = "io.circe" %% "circe-refined" % circeGeneric.revision
   val commonsIo = "commons-io" % "commons-io" % "2.11.0"
-  val coursierCore = "io.get-coursier" %% "coursier" % "2.0.16"
+  val coursierCore = "io.get-coursier" %% "coursier" % "2.1.0-M2-19-g5a34ba7c1"
   val cron4sCore = "com.github.alonsodomin.cron4s" %% "cron4s-core" % "0.6.1"
   val decline = "com.monovore" %% "decline" % "2.2.0"
   val disciplineMunit = "org.typelevel" %% "discipline-munit" % "1.0.9"
diff --git a/project/plugins.sbt b/project/plugins.sbt
index 71dac734..4f527a34 100644
--- a/project/plugins.sbt
+++ b/project/plugins.sbt
@@ -12,6 +12,3 @@ addSbtPlugin("pl.project13.scala" % "sbt-jmh" % "0.4.3")
 addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % "1.1.0")
 addSbtPlugin("org.scalameta" % "sbt-mdoc" % "2.2.24")
 addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.9.3")
-
-// This is only here so that Scala Steward updates the version in sbt/package.scala too.
-addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.9.34")


Test patch:
diff --git a/modules/core/src/test/scala/org/scalasteward/core/buildtool/sbt/SbtAlgTest.scala b/modules/core/src/test/scala/org/scalasteward/core/buildtool/sbt/SbtAlgTest.scala
index 1dde3de1..da6d6f1b 100644
--- a/modules/core/src/test/scala/org/scalasteward/core/buildtool/sbt/SbtAlgTest.scala
+++ b/modules/core/src/test/scala/org/scalasteward/core/buildtool/sbt/SbtAlgTest.scala
@@ -71,9 +71,18 @@ class SbtAlgTest extends FunSuite {
       Version("1.0.0"),
       Nel.of("github:functional-streams-for-scala/fs2/v1?sha=v1.0.5")
     )
-    val state = sbtAlg.runMigration(buildRoot, migration).runS(MockState.empty).unsafeRunSync()
-    val expected = MockState.empty.copy(
+    val initialState = MockState.empty
+      .addFiles(
+        mockRoot / s"workspace/store/versions/v2/https/repo1.maven.org/maven2/ch/epfl/scala/sbt-scalafix_2.12_1.0/versions.json" -> sbtScalafixVersionJson
+      )
+      .unsafeRunSync()
+    val state = sbtAlg.runMigration(buildRoot, migration).runS(initialState).unsafeRunSync()
+    val expected = initialState.copy(
       trace = Vector(
+        Cmd(
+          "read",
+          s"$mockRoot/workspace/store/versions/v2/https/repo1.maven.org/maven2/ch/epfl/scala/sbt-scalafix_2.12_1.0/versions.json"
+        ),
         Cmd("write", s"$mockRoot/.sbt/0.13/plugins/scala-steward-scalafix.sbt"),
         Cmd("write", s"$mockRoot/.sbt/1.0/plugins/scala-steward-scalafix.sbt"),
         Cmd(
@@ -107,9 +116,18 @@ class SbtAlgTest extends FunSuite {
       Nel.of("github:cb372/cats/Cats_v2_2_0?sha=235bd7c92e431ab1902db174cf4665b05e08f2f1"),
       scalacOptions = Some(Nel.of("-P:semanticdb:synthetics:on"))
     )
-    val state = sbtAlg.runMigration(buildRoot, migration).runS(MockState.empty).unsafeRunSync()
-    val expected = MockState.empty.copy(
+    val initialState = MockState.empty
+      .addFiles(
+        mockRoot / s"workspace/store/versions/v2/https/repo1.maven.org/maven2/ch/epfl/scala/sbt-scalafix_2.12_1.0/versions.json" -> sbtScalafixVersionJson
+      )
+      .unsafeRunSync()
+    val state = sbtAlg.runMigration(buildRoot, migration).runS(initialState).unsafeRunSync()
+    val expected = initialState.copy(
       trace = Vector(
+        Cmd(
+          "read",
+          s"$mockRoot/workspace/store/versions/v2/https/repo1.maven.org/maven2/ch/epfl/scala/sbt-scalafix_2.12_1.0/versions.json"
+        ),
         Cmd("write", s"$mockRoot/.sbt/0.13/plugins/scala-steward-scalafix.sbt"),
         Cmd("write", s"$mockRoot/.sbt/1.0/plugins/scala-steward-scalafix.sbt"),
         Cmd("write", s"$repoDir/scala-steward-scalafix-options.sbt"),
@@ -133,4 +151,13 @@ class SbtAlgTest extends FunSuite {
     )
     assertEquals(state, expected)
   }
+
+  private val sbtScalafixVersionJson =
+    s"""|{
+        |  "updatedAt" : 9999999999999,
+        |  "versions" : [
+        |    "0.9.33",
+        |    "0.9.34"
+        |  ]
+        |}""".stripMargin
 }