Skip to content

Commit 33ebd0d

Browse files
committed
Introduce new scalaVersionsByJvm setting
1 parent 50e75c5 commit 33ebd0d

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

src/main/scala/ScalaModulePlugin.scala

+31
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import com.typesafe.tools.mima.plugin.{MimaPlugin, MimaKeys}, MimaKeys._
66
object ScalaModulePlugin extends Plugin {
77
val repoName = settingKey[String]("The name of the repository under github.com/scala/.")
88
val mimaPreviousVersion = settingKey[Option[String]]("The version of this module to compare against when running MiMa.")
9+
val scalaVersionsByJvm = settingKey[Map[Int, List[(String, Boolean)]]]("For a Java major version (6, 8, 9), a list of Scala version and a flag indicating whether to use this combination for publishing.")
910

1011
private val canRunMima = taskKey[Boolean]("Decides if MiMa should run.")
1112
private val runMimaIfEnabled = taskKey[Unit]("Run MiMa if mimaPreviousVersion and the module can be resolved against the current scalaBinaryVersion.")
@@ -15,6 +16,36 @@ object ScalaModulePlugin extends Plugin {
1516

1617
mimaPreviousVersion := None,
1718

19+
scalaVersionsByJvm := Map.empty,
20+
21+
crossScalaVersions := {
22+
val OneDot = """1\.(\d).*""".r // 1.6, 1.8
23+
val Maj = """(\d+).*""".r // 9
24+
val javaVersion = System.getProperty("java.version") match {
25+
case OneDot(n) => n.toInt
26+
case Maj(n) => n.toInt
27+
case v => throw new RuntimeException(s"Unknown Java version: $v")
28+
}
29+
val isTravisPublishing = Option(System.getenv("TRAVIS_TAG")).getOrElse("").trim.nonEmpty
30+
val scalaVersions = scalaVersionsByJvm.value.getOrElse(javaVersion, Nil) collect {
31+
case (v, publish) if !isTravisPublishing || publish => v
32+
}
33+
if (scalaVersions.isEmpty) {
34+
val msg = s"No Scala version for Java major version $javaVersion. Adjust `scalaVersionsByJvm` in build.sbt."
35+
if (isTravisPublishing) {
36+
sLog.value.warn(msg)
37+
// Exit successfully, don't fail the (travis) build. This happens for example if `openjdk7`
38+
// is part of the travis configuration for testing, but it's not used for releasing against
39+
// any Scala version.
40+
System.exit(0)
41+
} else
42+
throw new RuntimeException(msg)
43+
}
44+
scalaVersions
45+
},
46+
47+
scalaVersion := crossScalaVersions.value.head,
48+
1849
organization := "org.scala-lang.modules",
1950

2051
// so we don't have to wait for sonatype to synch to maven central when deploying a new module

0 commit comments

Comments
 (0)