Skip to content

Commit 752edea

Browse files
authored
Merge pull request #55 from Philippus/provide-keys-though-autoimport
Provide keys through autoImport
2 parents 53b22b0 + 1a2140c commit 752edea

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

src/main/scala/ScalaModulePlugin.scala

+17-14
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,13 @@ import sbt.librarymanagement.ivy.IvyDependencyResolution
1111
import sbt.librarymanagement.{ UnresolvedWarningConfiguration, UpdateConfiguration }
1212

1313
object ScalaModulePlugin extends AutoPlugin {
14-
val repoName = settingKey[String]("The name of the repository under github.com/scala/.")
15-
val mimaPreviousVersion = settingKey[Option[String]]("The version of this module to compare against when running MiMa.")
16-
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.")
14+
object autoImport {
15+
val scalaModuleRepoName = settingKey[String]("The name of the repository under github.com/scala/.")
16+
val scalaModuleMimaPreviousVersion = settingKey[Option[String]]("The version of this module to compare against when running MiMa.")
17+
val scalaModuleScalaVersionsByJvm = 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.")
18+
val scalaModuleEnableOptimizerInlineFrom = settingKey[String]("The value passed to -opt-inline-from by `enableOptimizer` on 2.13 and higher.")
19+
}
20+
import autoImport._
1721

1822
// See https://github.com/sbt/sbt/issues/2082
1923
override def requires = plugins.JvmPlugin
@@ -22,7 +26,7 @@ object ScalaModulePlugin extends AutoPlugin {
2226

2327
// Settings in here are implicitly `in ThisBuild`
2428
override def buildSettings: Seq[Setting[_]] = Seq(
25-
scalaVersionsByJvm := Map.empty,
29+
scalaModuleScalaVersionsByJvm := Map.empty,
2630

2731
crossScalaVersions := {
2832
val OneDot = """1\.(\d).*""".r // 1.6, 1.8
@@ -36,7 +40,7 @@ object ScalaModulePlugin extends AutoPlugin {
3640
val isTravis = Option(System.getenv("TRAVIS")).exists(_ == "true") // `contains` doesn't exist in Scala 2.10
3741
val isTravisPublishing = Option(System.getenv("TRAVIS_TAG")).exists(_.trim.nonEmpty)
3842

39-
val byJvm = scalaVersionsByJvm.value
43+
val byJvm = scalaModuleScalaVersionsByJvm.value
4044
if (byJvm.isEmpty)
4145
throw new RuntimeException(s"Make sure to define `scalaVersionsByJvm in ThisBuild` in `build.sbt` in the root project, using the `ThisBuild` scope.")
4246

@@ -55,11 +59,10 @@ object ScalaModulePlugin extends AutoPlugin {
5559
}
5660
scalaVersions
5761
},
58-
enableOptimizerInlineFrom := "<sources>",
62+
scalaModuleEnableOptimizerInlineFrom := "<sources>",
5963
scalaVersion := crossScalaVersions.value.head
6064
)
6165

62-
val enableOptimizerInlineFrom = settingKey[String]("The value passed to -opt-inline-from by `enableOptimizer` on 2.13 and higher")
6366
/**
6467
* Enable `-opt:l:inline`, `-opt:l:classpath` or `-optimize`, depending on the scala version.
6568
*/
@@ -69,7 +72,7 @@ object ScalaModulePlugin extends AutoPlugin {
6972
(maj.toInt, min.toInt) match {
7073
case (m, _) if m < 12 => Seq("-optimize")
7174
case (12, n) if n < 3 => Seq("-opt:l:project")
72-
case _ => Seq("-opt:l:inline", "-opt-inline-from:" + enableOptimizerInlineFrom.value)
75+
case _ => Seq("-opt:l:inline", "-opt-inline-from:" + scalaModuleEnableOptimizerInlineFrom.value)
7376
}
7477
}
7578

@@ -88,7 +91,7 @@ object ScalaModulePlugin extends AutoPlugin {
8891
* To be included in the main sbt project of a Scala module.
8992
*/
9093
lazy val scalaModuleSettings: Seq[Setting[_]] = Seq(
91-
repoName := name.value,
94+
scalaModuleRepoName := name.value,
9295

9396
organization := "org.scala-lang.modules",
9497

@@ -128,7 +131,7 @@ object ScalaModulePlugin extends AutoPlugin {
128131
},
129132

130133
publishMavenStyle := true,
131-
scmInfo := Some(ScmInfo(url(s"https://github.com/scala/${repoName.value}"),s"scm:git:git://github.com/scala/${repoName.value}.git")),
134+
scmInfo := Some(ScmInfo(url(s"https://github.com/scala/${scalaModuleRepoName.value}"),s"scm:git:git://github.com/scala/${scalaModuleRepoName.value}.git")),
132135
homepage := Some(url("http://www.scala-lang.org/")),
133136
organizationHomepage := Some(url("http://www.scala-lang.org/")),
134137
licenses := Seq("Apache-2.0" -> url("https://www.apache.org/licenses/LICENSE-2.0")),
@@ -137,7 +140,7 @@ object ScalaModulePlugin extends AutoPlugin {
137140
pomExtra := (
138141
<issueManagement>
139142
<system>GitHub</system>
140-
<url>https://github.com/scala/{repoName.value}/issues</url>
143+
<url>https://github.com/scala/{scalaModuleRepoName.value}/issues</url>
141144
</issueManagement>
142145
<developers>
143146
<developer>
@@ -169,14 +172,14 @@ object ScalaModulePlugin extends AutoPlugin {
169172
private val runMimaIfEnabled = taskKey[Unit]("Run MiMa if mimaPreviousVersion and the module can be resolved against the current scalaBinaryVersion.")
170173

171174
private lazy val mimaSettings: Seq[Setting[_]] = MimaPlugin.mimaDefaultSettings ++ Seq(
172-
mimaPreviousVersion := None,
175+
scalaModuleMimaPreviousVersion := None,
173176

174177
// We're not using `%%` here in order to support both jvm and js projects (cross version `_2.12` / `_sjs0.6_2.12`)
175-
mimaPreviousArtifacts := mimaPreviousVersion.value.map(v => organization.value % moduleName.value % v cross crossVersion.value).toSet,
178+
mimaPreviousArtifacts := scalaModuleMimaPreviousVersion.value.map(v => organization.value % moduleName.value % v cross crossVersion.value).toSet,
176179

177180
canRunMima := {
178181
val log = streams.value.log
179-
mimaPreviousVersion.value match {
182+
scalaModuleMimaPreviousVersion.value match {
180183
case None =>
181184
log.warn("MiMa will NOT run because no mimaPreviousVersion is provided.")
182185
false

0 commit comments

Comments
 (0)