Skip to content

Commit

Permalink
Crossbuild for Scala3 (#105)
Browse files Browse the repository at this point in the history
  • Loading branch information
bcarter97 authored May 3, 2022
1 parent ea336f5 commit 3e14133
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 25 deletions.
19 changes: 19 additions & 0 deletions .scalafix3.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
rules = [
NoAutoTupling,
DisableSyntax,
LeakingImplicitClassVal,
NoValInForComprehension
]

OrganizeImports {
coalesceToWildcardImportThreshold = 8
expandRelative = true
groupedImports = Merge
importSelectorsOrder = SymbolsFirst
removeUnused = false
groups = [
"java."
"*"
"scala."
]
}
2 changes: 1 addition & 1 deletion .scalafmt.conf
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ maxColumn = 120
newlines.sometimesBeforeColonInMethodReturnType = false
project.git = true
rewrite.rules = [SortImports, RedundantBraces, RedundantParens, PreferCurlyFors]
runner.dialect = scala213
runner.dialect = scala3
spaces.beforeContextBoundColon = Always
style = defaultWithAlign
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
language: scala

scala:
- 2.13.7
- 3.1.1
jdk:
- openjdk12
- openjdk17

# Avoid triggering a duplicate build for PRs
branches:
Expand Down
35 changes: 28 additions & 7 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import Dependencies.all

lazy val scala3 = "3.1.1"
lazy val scala213 = "2.13.8"
lazy val scala212 = "2.12.15"
lazy val supportedScalaVersions = List(scala213, scala212)
lazy val supportedScalaVersions = List(scala3, scala213, scala212)
lazy val scmUrl = "https://github.com/sky-uk/kafka-topic-loader"

name := "kafka-topic-loader"
Expand All @@ -21,7 +20,7 @@ developers := List(
)
)

scalaVersion := scala213
scalaVersion := scala3
crossScalaVersions := supportedScalaVersions
semanticdbEnabled := true
semanticdbVersion := scalafixSemanticdb.revision
Expand All @@ -30,19 +29,41 @@ tpolecatScalacOptions ++= Set(ScalacOptions.source3)

ThisBuild / scalacOptions ++= Seq("-explaintypes") ++ {
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, 13)) => Seq("-Wconf:msg=annotation:silent")
case _ => Nil
case Some((3, _)) | Some((2, 13)) => Seq("-Wconf:msg=annotation:silent")
case _ => Nil
}
}

ThisBuild / scalafixDependencies += Dependencies.Plugins.organizeImports

/** Scala 3 doesn't support two rules yet - RemoveUnused and ProcedureSyntax. So we require a different scalafix config
* for Scala 3
*
* RemoveUnused relies on -warn-unused which isn't available in scala 3 yet -
* https://scalacenter.github.io/scalafix/docs/rules/RemoveUnused.html
*
* ProcedureSyntax doesn't exist in Scala 3 - https://scalacenter.github.io/scalafix/docs/rules/ProcedureSyntax.html
*/
scalafixConfig := {
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((3, _)) => Some((ThisBuild / baseDirectory).value / ".scalafix3.conf")
case _ => None
}
}

Test / parallelExecution := false
Test / fork := true

Global / onChangedBuildSource := ReloadOnSourceChanges

libraryDependencies ++= all
libraryDependencies ++= Dependencies.all

excludeDependencies ++= {
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((3, _)) => Dependencies.scala3Exclusions
case _ => Seq.empty
}
}

addCommandAlias("checkFix", "scalafixAll --check OrganizeImports; scalafixAll --check")
addCommandAlias("runFix", "scalafixAll OrganizeImports; scalafixAll")
Expand Down
15 changes: 10 additions & 5 deletions project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ object Dependencies {

object Akka {
private val version = "2.6.19"
val stream = "com.typesafe.akka" %% "akka-stream" % version
val streamKafka = "com.typesafe.akka" %% "akka-stream-kafka" % "2.1.1"
val streamTestkit = "com.typesafe.akka" %% "akka-stream-testkit" % version % Test
val testkit = "com.typesafe.akka" %% "akka-testkit" % version % Test
val stream = "com.typesafe.akka" %% "akka-stream" % version cross CrossVersion.for3Use2_13
val streamKafka = "com.typesafe.akka" %% "akka-stream-kafka" % "2.1.1" cross CrossVersion.for3Use2_13
val streamTestkit = "com.typesafe.akka" %% "akka-stream-testkit" % version % Test cross CrossVersion.for3Use2_13
val testkit = "com.typesafe.akka" %% "akka-testkit" % version % Test cross CrossVersion.for3Use2_13
val base = Seq(stream, streamKafka)
val test = Seq(streamTestkit, testkit)
}
Expand All @@ -28,9 +28,14 @@ object Dependencies {
val logbackClassic = "ch.qos.logback" % "logback-classic" % "1.2.11" % Runtime
val scalaCollectionCompat = "org.scala-lang.modules" %% "scala-collection-compat" % "2.7.0"

val embeddedKafka = "io.github.embeddedkafka" %% "embedded-kafka" % "3.1.0" % Test
val embeddedKafka = "io.github.embeddedkafka" %% "embedded-kafka" % "3.1.0" % Test cross CrossVersion.for3Use2_13
val scalaTest = "org.scalatest" %% "scalatest" % "3.2.12" % Test

val scala3Exclusions = Seq(
"com.typesafe.scala-logging" % "scala-logging_2.13",
"org.scala-lang.modules" % "scala-collection-compat_2.13"
)

val core = Akka.base ++ Cats.all ++ Seq(
kafkaClients,
scalaLogging,
Expand Down
6 changes: 3 additions & 3 deletions src/test/scala/base/IntegrationSpecBase.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ import scala.jdk.CollectionConverters._

abstract class IntegrationSpecBase extends WordSpecBase with Eventually {

override implicit val patienceConfig = PatienceConfig(20.seconds, 200.millis)
override implicit val patienceConfig: PatienceConfig = PatienceConfig(20.seconds, 200.millis)

implicit val timeout = Timeout(5.seconds)
implicit val timeout: Timeout = Timeout(5.seconds)

trait TestContext extends AkkaSpecBase with EmbeddedKafka {

implicit lazy val kafkaConfig =
implicit lazy val kafkaConfig: EmbeddedKafkaConfig =
EmbeddedKafkaConfig(kafkaPort = RandomPort(), zooKeeperPort = RandomPort(), Map("log.roll.ms" -> "10"))

override implicit lazy val system: ActorSystem = ActorSystem(
Expand Down
4 changes: 2 additions & 2 deletions src/test/scala/integration/DeprecatedMethodsIntSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,13 @@ class DeprecatedMethodsIntSpec extends IntegrationSpecBase {
.runWith(Sink.ignore)
.futureValue shouldBe Done

store.getRecords.futureValue.map(_.partition) should contain only (partitionsToRead.toList: _*)
store.getRecords.futureValue.map(_.partition).toSet should contain theSameElementsAs partitionsToRead.toList
}
}
}

class RecordStore()(implicit system: ActorSystem) {
private val storeActor = system.actorOf(Props(classOf[Store], RecordStore.this))
private val storeActor = system.actorOf(Props(new Store))

def storeRecord(rec: ConsumerRecord[String, String])(implicit timeout: Timeout): Future[Int] =
(storeActor ? rec).mapTo[Int]
Expand Down
9 changes: 4 additions & 5 deletions src/test/scala/utils/RandomPort.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ package utils

import java.net.ServerSocket

import scala.util.Using

object RandomPort {
def apply(): Int = {
val socket = new ServerSocket(0)
def apply(): Int = Using.resource(new ServerSocket(0)) { socket =>
socket.setReuseAddress(true)
val port = socket.getLocalPort
socket.close()
port
socket.getLocalPort
}
}

0 comments on commit 3e14133

Please sign in to comment.