diff --git a/build.sbt b/build.sbt index 2985740..cf3ca66 100644 --- a/build.sbt +++ b/build.sbt @@ -1,5 +1,8 @@ val buildName = "jardiff" +val scala212Version = "2.12.18" +val scala213Version = "2.13.12" + inThisBuild(Seq[Setting[_]]( organization := "com.lightbend", scalaVersion := "2.13.12", @@ -49,6 +52,8 @@ lazy val root = ( settings( name := buildName, publish / skip := true, + // See https://github.com/sbt/sbt/issues/4262#issuecomment-405607763 + crossScalaVersions := Seq.empty ) ) @@ -66,7 +71,9 @@ lazy val core = project. "ch.qos.logback" % "logback-classic" % "1.3.11", "org.scalatest" %% "scalatest" % "3.2.17" % Test, ), - name := buildName + "-core" + name := buildName + "-core", + crossScalaVersions := Seq(scala212Version, scala213Version), + scalaVersion := scala212Version ) lazy val cli = project. @@ -80,6 +87,11 @@ lazy val cli = project. case x if x.endsWith("module-info.class") => MergeStrategy.discard case x => (assembly / assemblyMergeStrategy).value(x) }, + // Having Scala 2.13 here in crossScalaVersions is redundant but due to how + // sbt-github-actions generates the sbt test command (i.e. sbt '++ 2.13.12' test), + // sbt's update task cannot handle projects with different crossScalaVersions well + crossScalaVersions := Seq(scala212Version, scala213Version), + scalaVersion := scala212Version, // cli is not meant to be published publish / skip := true, ).dependsOn(core) diff --git a/cli/src/main/scala/scala/tools/jardiff/Main.scala b/cli/src/main/scala/scala/tools/jardiff/Main.scala index cdf08b9..36e5df7 100644 --- a/cli/src/main/scala/scala/tools/jardiff/Main.scala +++ b/cli/src/main/scala/scala/tools/jardiff/Main.scala @@ -4,6 +4,8 @@ package scala.tools.jardiff +import JDKCollectionConvertersCompat.Converters._ + import java.io.{ByteArrayOutputStream, File, PrintWriter} import java.nio.file._ @@ -11,7 +13,6 @@ import org.apache.commons.cli import org.apache.commons.cli.{CommandLine, DefaultParser, HelpFormatter, Options} import org.eclipse.jgit.util.io.NullOutputStream -import scala.jdk.CollectionConverters._ import scala.util.Try import scala.util.control.NonFatal diff --git a/core/src/main/scala/scala/tools/jardiff/AsmTextifyRenderer.scala b/core/src/main/scala/scala/tools/jardiff/AsmTextifyRenderer.scala index c7b65a6..fefa357 100644 --- a/core/src/main/scala/scala/tools/jardiff/AsmTextifyRenderer.scala +++ b/core/src/main/scala/scala/tools/jardiff/AsmTextifyRenderer.scala @@ -4,10 +4,11 @@ package scala.tools.jardiff +import JDKCollectionConvertersCompat.Converters._ + import java.io.PrintWriter import java.nio.file.{Files, Path} -import scala.jdk.CollectionConverters._ import org.objectweb.asm.{ClassReader, Opcodes} import org.objectweb.asm.tree.{ClassNode, FieldNode, InnerClassNode, MethodNode} import org.objectweb.asm.util.TraceClassVisitor diff --git a/core/src/main/scala/scala/tools/jardiff/JDKCollectionConvertersCompat.scala b/core/src/main/scala/scala/tools/jardiff/JDKCollectionConvertersCompat.scala new file mode 100644 index 0000000..0cf4ebb --- /dev/null +++ b/core/src/main/scala/scala/tools/jardiff/JDKCollectionConvertersCompat.scala @@ -0,0 +1,31 @@ +package scala.tools.jardiff + +import scala.annotation.nowarn + +/** Magic to get cross-compiling access to `scala.jdk.CollectionConverters` + * with a fallback on `scala.collection.JavaConverters`, without deprecation + * warning in any Scala version. + * + * @see https://github.com/scala/scala-collection-compat/issues/208 + */ +@nowarn("msg=Unused import") +private[jardiff] object JDKCollectionConvertersCompat { + object Scope1 { + object jdk { + type CollectionConverters = Int + } + } + import Scope1._ + + object Scope2 { + import scala.collection.{JavaConverters => CollectionConverters} + + object Inner { + import scala._ + import jdk.CollectionConverters + val Converters = CollectionConverters + } + } + + val Converters = Scope2.Inner.Converters +} diff --git a/core/src/main/scala/scala/tools/jardiff/JarDiff.scala b/core/src/main/scala/scala/tools/jardiff/JarDiff.scala index d96301c..8b14603 100644 --- a/core/src/main/scala/scala/tools/jardiff/JarDiff.scala +++ b/core/src/main/scala/scala/tools/jardiff/JarDiff.scala @@ -4,6 +4,8 @@ package scala.tools.jardiff +import JDKCollectionConvertersCompat.Converters._ + import java.io.{File, OutputStream} import java.nio.file._ import java.nio.file.attribute.BasicFileAttributes @@ -14,7 +16,6 @@ import org.eclipse.jgit.lib.RepositoryCache import org.eclipse.jgit.revwalk.RevCommit import scala.tools.jardiff.JGitUtil._ -import scala.jdk.CollectionConverters._ final class JarDiff(files: List[List[Path]], config: JarDiff.Config, renderers: String => List[FileRenderer]) { private val targetBase = config.gitRepo.getOrElse(Files.createTempDirectory("jardiff-"))