Skip to content

Commit

Permalink
* conditional load of some modules based on Java version
Browse files Browse the repository at this point in the history
  • Loading branch information
benedeki committed Nov 21, 2024
1 parent 45e137f commit 7e86f6c
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 31 deletions.
85 changes: 54 additions & 31 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,25 @@ import Dependencies.*
import Dependencies.Versions.spark3
import VersionAxes.*

ThisBuild / scalaVersion := Setup.scala213.asString

ThisBuild / versionScheme := Some("early-semver")

Global / onChangedBuildSource := ReloadOnSourceChanges

val limitedProject: Boolean = Setup.currentJava < Setup.recommendedJava

initialize := {
val _ = initialize.value // Ensure previous initializations are run

val requiredJavaVersion = VersionNumber("11")
val currentJavaVersion = VersionNumber(sys.props("java.specification.version"))
println(s"Running on Java version $currentJavaVersion, required is at least version $requiredJavaVersion")
//this routine can be used to assert the required Java version
assert(Setup.currentJava >= Setup.requiredJava,
s"Running on Java version ${Setup.currentJava}, required is at least version ${Setup.requiredJava}, recommended is ${Setup.recommendedJava}")

if (limitedProject) {
val log = Keys.sLog.value
log.warn(s"Some nodules will not be loaded, because they require at least Java ${Setup.recommendedJava} while Java ${Setup.currentJava} has been found")
log.warn("""Affected modules are: "atum-server", "atum-database"""")
}
}

enablePlugins(FlywayPlugin)
Expand All @@ -45,23 +53,31 @@ libraryDependencies ++= flywayDependencies
/**
* Module `server` is the service application that collects and stores measured data And upo request retrives them
*/
lazy val server = (projectMatrix in file("server"))
.settings(
Setup.commonSettings ++ Seq(
name := "atum-server",
javacOptions ++= Setup.serverAndDbJavacOptions,
Compile / packageBin / publishArtifact := false,
packageBin := (Compile / assembly).value,
artifactPath / (Compile / packageBin) := baseDirectory.value / s"target/${name.value}-${version.value}.jar",
testFrameworks += new TestFramework("zio.test.sbt.ZTestFramework"),
Setup.serverMergeStrategy,
publish / skip := true
): _*
)
.enablePlugins(AssemblyPlugin)
.enablePlugins(AutomateHeaderPlugin)
.addSingleScalaBuild(Setup.serverAndDbScalaVersion, Dependencies.serverDependencies)
.dependsOn(model)
lazy val server = {
val server = (projectMatrix in file("server"))
.settings(
Setup.commonSettings ++ Seq(
name := "atum-server",
javacOptions ++= Setup.serverAndDbJavacOptions,
Compile / packageBin / publishArtifact := false,
packageBin := (Compile / assembly).value,
artifactPath / (Compile / packageBin) := baseDirectory.value / s"target/${name.value}-${version.value}.jar",
testFrameworks += new TestFramework("zio.test.sbt.ZTestFramework"),
Setup.serverMergeStrategy,
publish / skip := true
): _*
)
.enablePlugins(AssemblyPlugin)
.enablePlugins(AutomateHeaderPlugin)
.addSingleScalaBuild(Setup.serverAndDbScalaVersion, Dependencies.serverDependencies)
.dependsOn(model)

if (limitedProject) {
null // if value other then null is returned, the condition doesn't seem to work.
} else {
server
}
}

/**
* Module `agent` is the library to be plugged into the Spark application to measure the data and send it to the server
Expand Down Expand Up @@ -93,16 +109,23 @@ lazy val model = (projectMatrix in file("model"))
/**
* Module `database` is the source of database structures of the service
*/
lazy val database = (projectMatrix in file("database"))
.disablePlugins(sbtassembly.AssemblyPlugin)
.settings(
Setup.commonSettings ++ Seq(
name := "atum-database",
javacOptions ++= Setup.serverAndDbJavacOptions,
publish / skip := true
): _*
)
.addSingleScalaBuild(Setup.serverAndDbScalaVersion, Dependencies.databaseDependencies)
lazy val database = {
val database = (projectMatrix in file("database"))
.disablePlugins(sbtassembly.AssemblyPlugin)
.settings(
Setup.commonSettings ++ Seq(
name := "atum-database",
javacOptions ++= Setup.serverAndDbJavacOptions,
publish / skip := true
): _*
)
.addSingleScalaBuild(Setup.serverAndDbScalaVersion, Dependencies.databaseDependencies)
if (limitedProject) {
null // if value other then null is returned, the condition doesn't seem to work.
} else {
database
}
}

/**
* Module `reader` is the library to be plugged into application which wants to easily read the measured data stored on
Expand Down
5 changes: 5 additions & 0 deletions project/Setup.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ import za.co.absa.commons.version.Version


object Setup {
//supprtted Java versions
val requiredJava: Double = "1.8".toDouble
val recommendedJava: Double = "11".toDouble
val currentJava: Double = sys.props("java.specification.version").toDouble

//supported Scala versions
val scala211: Version = Version.asSemVer("2.11.12")
val scala212: Version = Version.asSemVer("2.12.18")
Expand Down

0 comments on commit 7e86f6c

Please sign in to comment.