import Dependencies._ def scala211 = "2.11.12" def scala212 = "2.12.9" def scala213 = "2.13.1" organization := "io.stasis" name := "stasis" def scalacOptionsForVersion(version: String): Seq[String] = { // format: off val defaultOpts = Seq( "-deprecation", // Emit warning and location for usages of deprecated APIs. "-encoding", "utf-8", // Specify character encoding used by source files. "-explaintypes", // Explain type errors in more detail. "-feature", // Emit warning and location for usages of features that should be imported explicitly. "-language:existentials", // Existential types (besides wildcard types) can be written and inferred "-language:experimental.macros", // Allow macro definition (besides implementation and application) "-language:higherKinds", // Allow higher-kinded types "-language:implicitConversions", // Allow definition of implicit functions called views "-unchecked", // Enable additional warnings where generated code depends on assumptions. "-Xcheckinit", // Wrap field accessors to throw an exception on uninitialized access. "-Xlint:adapted-args", // Warn if an argument list is modified to match the receiver. "-Xlint:constant", // Evaluation of a constant arithmetic expression results in an error. "-Xlint:delayedinit-select", // Selecting member of DelayedInit. "-Xlint:doc-detached", // A Scaladoc comment appears to be detached from its element. "-Xlint:inaccessible", // Warn about inaccessible types in method signatures. "-Xlint:infer-any", // Warn when a type argument is inferred to be `Any`. "-Xlint:missing-interpolator", // A string literal appears to be missing an interpolator id. "-Xlint:nullary-override", // Warn when non-nullary `def f()' overrides nullary `def f'. "-Xlint:nullary-unit", // Warn when nullary methods return Unit. "-Xlint:option-implicit", // Option.apply used implicit view. "-Xlint:package-object-classes", // Class or object defined in package object. "-Xlint:poly-implicit-overload", // Parameterized overloaded implicit methods are not visible as view bounds. "-Xlint:private-shadow", // A private field (or class parameter) shadows a superclass field. "-Xlint:stars-align", // Pattern sequence wildcard must align with sequence component. "-Xlint:type-parameter-shadow", // A local type parameter shadows a type already in scope. "-Ywarn-dead-code", // Warn when dead code is identified. "-Ywarn-extra-implicit", // Warn when more than one implicit parameter section is defined. "-Ywarn-numeric-widen", // Warn when numerics are widened. "-Ywarn-unused:implicits", // Warn if an implicit parameter is unused. "-Ywarn-unused:imports", // Warn if an import selector is not referenced. "-Ywarn-unused:locals", // Warn if a local definition is unused. "-Ywarn-unused:params", // Warn if a value parameter is unused. "-Ywarn-unused:patvars", // Warn if a variable bound in a pattern is unused. "-Ywarn-unused:privates", // Warn if a private member is unused. "-Ywarn-value-discard", // Warn when non-Unit expression results are unused. ) val versionOpts: Seq[String] = CrossVersion.partialVersion(version) match { case Some((2, major)) if major < 13 => Seq( "-Xlint:by-name-right-associative", // By-name parameter of right associative operator. "-Xlint:unsound-match", // Pattern match may not be typesafe. "-Xfatal-warnings", // Fail the compilation if there are any warnings. "-Xfuture", // Turn on future language features. "-Yno-adapted-args", // Do not adapt an argument list (either by inserting () or creating a tuple) to match the receiver. "-Ypartial-unification", // Enable partial unification in type constructor inference "-Ywarn-inaccessible", // Warn about inaccessible types in method signatures. "-Ywarn-infer-any", // Warn when a type argument is inferred to be `Any`. "-Ywarn-nullary-override", // Warn when non-nullary `def f()' overrides nullary `def f'. "-Ywarn-nullary-unit", // Warn when nullary methods return Unit. ) case _ => Seq() } defaultOpts ++ versionOpts // format: on } addCompilerPlugin( ("org.typelevel" %% "kind-projector" % "0.10.3").cross(CrossVersion.binary), ) inThisBuild( Seq( organization := "io.stasis", homepage := Some(url("https://github.com/stasis/stasis")), licenses := List( "Apache-2.0" -> url("http://www.apache.org/licenses/LICENSE-2.0"), "ASM" -> url("https://asm.ow2.io/license.html") ), developers := List( Developer( "gburd", "Gregory Burd", "greg@burd.me", url("https://greg.burd.me") ) ), scalaVersion := scala213, crossScalaVersions := List(scala213, scala212, scala211), resolvers += Resolver.sonatypeRepo("releases"), scalacOptions ++= scalacOptionsForVersion(scalaVersion.value), libraryDependencies ++= Seq( scalatest.value % Test, scalacheck % Test, scalametaTestkit % Test, ), scalacOptions ++= { CrossVersion.partialVersion(scalaVersion.value) match { case Some((2, 11)) => Seq("-target:jvm-1.8") case Some((2, 12)) => Seq("-target:jvm-1.8") case Some((2, 13)) => Seq("-target:jvm-1.12") case _ => Seq.empty } }, Test / testOptions += Tests.Argument(TestFrameworks.JUnit, "-q", "-v", "-a") ) ) skip in publish := true commands += Command.command("ci-test") { s => val scalaVersion = sys.env.get("TEST") match { case Some("2.11") => scala211 case Some("2.12") => scala212 case Some("2.13") => scala213 case _ => scala212 } val docsTest = if (scalaVersion == scala213) "docs/run" else "version" s"++$scalaVersion" :: s"tests/test" :: s"coreJS/test" :: docsTest :: s } lazy val core = project .in(file("stasis-core")) .settings( moduleName := "stasis-core", description := "Implementation of Stasis", buildInfoSettings, buildInfoPackage := "io.stasis", buildInfoObject := "BuildInfo", projectDependencies ++= Seq( scalatest.value % Test, scalametaTestkit % Test ) ) .enablePlugins(BuildInfoPlugin) lazy val persist = project .in(file("stasis-persist")) .settings( moduleName := "stasis-persist", assemblyJarName.in(assembly) := "stasis-persist.jar", ) .dependsOn(core, rep) lazy val rep = project .in(file("stasis-rep")) .settings( moduleName := "stasis-rep", assemblyJarName.in(assembly) := "stasis-rep.jar" ) .dependsOn(core) val testLibraryDependencies = Seq ( "junit" % "junit" % "4.12" % Test, "com.novocode" % "junit-interface" % "0.11" % Test ) lazy val test = project .in(file("stasis-test")) .settings( moduleName := "stasis-test", assemblyJarName.in(assembly) := "stasis-test.jar", Test / fork := true, Test / logBuffered := false, Test / parallelExecution := false, Test / testOptions := Seq(Tests.Argument(TestFrameworks.JUnit,"-a", "-q", "-v")), Test / javacOptions := Seq( "-Xlint:deprecation", "-Xlint:unchecked", s"-Dscala.version=${scalaVersion}" ), Test / javaOptions := { val basedir = (baseDirectory in ThisBuild).value.getCanonicalFile val builddir = basedir + "/target" val unittestdir = builddir + "/test" val docdir = basedir + "/docs" val docletsrcdir = docdir + "/doclet" Seq( "-DJE_TEST=true", s"-Dbasedir=${basedir}", s"-Ddist.srcdir=${basedir}/dist", s"-Dunittest.srcdir=${basedir}/test", s"-Dunittest.dir=${unittestdir}", s"-Dunittest.destdir=${unittestdir}/classes", s"-Dunittest.envdirroot=${unittestdir}/envdata", s"-Dunittest.failures=${unittestdir}/failures", s"-Dunittest.copylimit=10", s"-Dunittest.datadir=${unittestdir}/data", s"-Dunittest.extraenvdir=${unittestdir}/propTest", s"-Dunittest.extraenvdir2=${unittestdir}/propTest2", s"-Dunittest.reportsdir=${unittestdir}/reports", s"-Dunittest.testclassloader=${unittestdir}/testclassloader", s"-Dunittest.testserialdir=${unittestdir}/testserial", s"-Dunittest.testevolvedir=${unittestdir}/testevolve", s"-Dunittest.serialtest.bdb=${unittestdir}/StoredClassCatalogTest-bdb", s"-Dunittest.serialtest.txn=${unittestdir}/StoredClassCatalogTest-txn", s"-Dunittest.showoutput=true", s"-Ddoc.dir=${docdir}", s"-Ddoc.javadir=${docdir}/java", s"-Ddoc.internaljavadir=${docdir}/internal-javadoc", s"-Ddoc.examplesdir=${docdir}/examples", s"-Ddoc.scratchdir=${builddir}/tmp", s"-Ddocsrc.dir=${basedir}/docs_src", s"-Ddoclet.src.dir=${docletsrcdir}", s"-Ddoclet.classes.dir=${docletsrcdir}/Classes", s"-Ddoclet.jar=${docdir}/HidingDoclet.jar", ) }, libraryDependencies ++= testLibraryDependencies ) .disablePlugins(plugins.JUnitXmlReportPlugin) .dependsOn(core, persist, rep) val testJavacOptions =Seq( "-Xlint:deprecation", "-Xlint:unchecked" ) lazy val test_examples = project .in(file("stasis-test-examples")) .settings( moduleName := "stasis-test-examples", assemblyJarName.in(assembly) := "stasis-test-examples.jar", Test / javacOptions := testJavacOptions, libraryDependencies ++= testLibraryDependencies ) .dependsOn(core, persist, rep, test) lazy val test_dpl_v0 = project .in(file("stasis-test-dpl-v0")) .settings( moduleName := "stasis-test-dpl-v0", assemblyJarName.in(assembly) := "stasis-test-dpl-v0.jar", Test / javacOptions := testJavacOptions, libraryDependencies ++= testLibraryDependencies ) .dependsOn(core, persist, rep, test) lazy val test_dpl_v1 = project .in(file("stasis-test-dpl-v1")) .settings( moduleName := "stasis-test-dpl-v1", assemblyJarName.in(assembly) := "stasis-test-dpl-v1.jar", Test / javacOptions := testJavacOptions, libraryDependencies ++= testLibraryDependencies ) .dependsOn(core, persist, rep, test) val V = "\\d+\\.\\d+\\.\\d+" val ReleaseCandidate = s"($V-RC\\d+).*".r val Milestone = s"($V-M\\d+).*".r lazy val stableVersion = Def.setting { version.in(ThisBuild).value.replaceAll("\\+.*", "") } lazy val buildInfoSettings: Seq[Def.Setting[_]] = Seq( buildInfoKeys := Seq[BuildInfoKey]( name, version, "scalameta" -> scalametaV, "nightly" -> version.value, "stable" -> stableVersion.value, "scala" -> scalaVersion.value, "scala211" -> scala211, "scala212" -> scala212, "scala213" -> scala213, "coursier" -> coursier, "commit" -> sys.process.Process("git rev-parse HEAD").lineStream_!.head, "timestamp" -> System.currentTimeMillis().toString, scalaVersion, sbtVersion ), buildInfoPackage := "io.stasis", buildInfoObject := "Versions" ) // Filter out compiler flags to make the repl experience functional... val badConsoleFlags = Seq("-Xfatal-warnings", "-Ywarn-unused:imports") scalacOptions in (Compile, console) ~= (_.filterNot(badConsoleFlags.contains(_))) enablePlugins(ScalafmtPlugin, JavaAppPackaging, GhpagesPlugin, MicrositesPlugin, TutPlugin)