Skip to content

Commit b7dae14

Browse files
committed
move scala and cross publish settings into plugins 🚀
1 parent 534bf06 commit b7dae14

4 files changed

Lines changed: 52 additions & 12 deletions

File tree

build.sbt

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,18 @@
1-
val commonSettings = Seq(
2-
organization := "com.htmlism",
3-
scalaVersion := "2.13.18",
4-
crossScalaVersions := Seq("2.13.18"),
5-
scalacOptions += "-Xsource:3"
6-
)
7-
81
lazy val core = Project("spawning-pool-core", file("spawning-pool-core"))
9-
.settings(commonSettings*)
102
.settings(specs2*)
113
.settings(betterConsole)
124

135
lazy val coreAlpha =
146
Project("spawning-pool-core-alpha", file("spawning-pool-core-alpha"))
15-
.settings(commonSettings*)
167
.settings(fs2*)
178
.settings(specs2*)
189
.settings(betterConsole)
1910

2011
lazy val coreCats =
2112
Project("spawning-pool-scalaz", file("spawning-pool-scalaz"))
22-
.settings(commonSettings*)
2313
.dependsOn(coreAlpha)
2414

2515
lazy val benchmark = project
26-
.settings(commonSettings*)
2716
.dependsOn(core)
2817

2918
lazy val storage =
@@ -33,7 +22,6 @@ lazy val storage =
3322
.withYaml
3423

3524
lazy val root = Project("spawning-pool", file("."))
36-
.settings(commonSettings*)
3725
.aggregate(core, benchmark, coreAlpha, storage)
3826

3927
publishArtifact := false
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import sbt.Keys.*
2+
import sbt.*
3+
4+
/**
5+
* Automatically enriches projects with the following settings (despite the word "override").
6+
*/
7+
object CrossPublish2And3Plugin extends AutoPlugin {
8+
9+
/**
10+
* Thus plug-in will automatically be enabled; it has no requirements.
11+
*/
12+
override def trigger: PluginTrigger = AllRequirements
13+
14+
override val buildSettings: Seq[Setting[?]] = Seq(
15+
crossScalaVersions := Seq("2.13.18")
16+
)
17+
}

project/ProjectPlugin.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ object ProjectPlugin extends AutoPlugin {
1616
*/
1717
override def trigger: PluginTrigger = AllRequirements
1818

19+
override val buildSettings: Seq[Setting[?]] = Seq(
20+
organization := "com.htmlism"
21+
)
22+
1923
object ThingsToAutoImport {
2024
private def jarName(s: String) =
2125
"spawning-pool-" + s

project/Scala2Plugin.scala

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import sbt.Keys.*
2+
import sbt.*
3+
4+
/**
5+
* Automatically enriches projects with the following settings (despite the word "override").
6+
*/
7+
object Scala2Plugin extends AutoPlugin {
8+
9+
/**
10+
* Thus plug-in will automatically be enabled; it has no requirements.
11+
*/
12+
override def trigger: PluginTrigger = AllRequirements
13+
14+
override val buildSettings: Seq[Setting[?]] = Seq(
15+
scalaVersion := "2.13.18"
16+
)
17+
18+
// putting into project settings helps with late binding for properly detecting scala3 cross build
19+
override val projectSettings: Seq[Setting[?]] = Seq(
20+
scalacOptions ++= scala3Syntax(scalaVersion.value)
21+
)
22+
23+
private def scala3Syntax(s: String) =
24+
CrossVersion.partialVersion(s) match {
25+
case Some((2, _)) =>
26+
Seq("-Xsource:3")
27+
28+
case _ =>
29+
Nil
30+
}
31+
}

0 commit comments

Comments
 (0)