Skip to content

Drop scalaVersionsByJvm and add sbt-travisci #62

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,6 @@ repoName := "<GitHub repo name>" // the repo under github.com/scala/, only r
organization := "<org>" // only required if different from "org.scala-lang.modules"
version := "<module version>"

// The plugin uses `scalaVersionsByJvm` to set `crossScalaVersions in ThisBuild` according to the JVM major version.
// The `scalaVersion in ThisBuild` is set to `crossScalaVersions.value.head`.
scalaVersionsByJvm in ThisBuild := {
val v211 = "2.11.12"
val v212 = "2.12.8"
val v213 = "2.13.0-RC1"
// Map[JvmMajorVersion, List[(ScalaVersion, UseForPublishing)]]
Map(
8 -> List(v211 -> true, v212 -> true, v213 -> true),
9 -> List(v211, v212, v213).map(_ -> false))
}

mimaPreviousVersion := Some("1.0.0") // enables MiMa (`None` by default, which disables it)

OsgiKeys.exportPackage := Seq(s"<exported package>;version=${version.value}")
Expand Down
1 change: 1 addition & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ licenses := Seq(("Apache-2.0", url("https://www.apache.org/licenses/L

addSbtPlugin("com.typesafe.sbt" % "sbt-osgi" % "0.9.5")
addSbtPlugin("com.typesafe" % "sbt-mima-plugin" % "0.5.0")
addSbtPlugin("com.dwijnand" % "sbt-travisci" % "1.2.0")
37 changes: 1 addition & 36 deletions src/main/scala/ScalaModulePlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import sbt.librarymanagement.{ UnresolvedWarningConfiguration, UpdateConfigurati
object ScalaModulePlugin extends AutoPlugin {
val repoName = settingKey[String]("The name of the repository under github.com/scala/.")
val mimaPreviousVersion = settingKey[Option[String]]("The version of this module to compare against when running MiMa.")
val scalaVersionsByJvm = settingKey[Map[Int, List[(String, Boolean)]]]("For a Java major version (6, 8, 9), a list of a Scala version and a flag indicating whether to use this combination for publishing.")

// See https://github.com/sbt/sbt/issues/2082
override def requires = plugins.JvmPlugin
Expand All @@ -22,41 +21,7 @@ object ScalaModulePlugin extends AutoPlugin {

// Settings in here are implicitly `in ThisBuild`
override def buildSettings: Seq[Setting[_]] = Seq(
scalaVersionsByJvm := Map.empty,

crossScalaVersions := {
val OneDot = """1\.(\d).*""".r // 1.6, 1.8
val Maj = """(\d+).*""".r // 9
val javaVersion = System.getProperty("java.version") match {
case OneDot(n) => n.toInt
case Maj(n) => n.toInt
case v => throw new RuntimeException(s"Unknown Java version: $v")
}

val isTravis = Option(System.getenv("TRAVIS")).exists(_ == "true") // `contains` doesn't exist in Scala 2.10
val isTravisPublishing = Option(System.getenv("TRAVIS_TAG")).exists(_.trim.nonEmpty)

val byJvm = scalaVersionsByJvm.value
if (byJvm.isEmpty)
throw new RuntimeException(s"Make sure to define `scalaVersionsByJvm in ThisBuild` in `build.sbt` in the root project, using the `ThisBuild` scope.")

val scalaVersions = byJvm.getOrElse(javaVersion, Nil) collect {
case (v, publish) if !isTravisPublishing || publish => v
}
if (scalaVersions.isEmpty) {
if (isTravis) {
sLog.value.warn(s"No Scala version in `scalaVersionsByJvm` in build.sbt needs to be released on Java major version $javaVersion.")
// Exit successfully, don't fail the (travis) build. This happens for example if `openjdk7`
// is part of the travis configuration for testing, but it's not used for releasing against
// any Scala version.
System.exit(0)
} else
throw new RuntimeException(s"No Scala version for Java major version $javaVersion. Change your Java version or adjust `scalaVersionsByJvm` in build.sbt.")
}
scalaVersions
},
enableOptimizerInlineFrom := "<sources>",
scalaVersion := crossScalaVersions.value.head
enableOptimizerInlineFrom := "<sources>"
)

val enableOptimizerInlineFrom = settingKey[String]("The value passed to -opt-inline-from by `enableOptimizer` on 2.13 and higher")
Expand Down