Skip to content

Commit

Permalink
Refactor the build file
Browse files Browse the repository at this point in the history
  • Loading branch information
hosamaly committed Mar 9, 2018
1 parent 3655c47 commit 8b475db
Showing 1 changed file with 36 additions and 31 deletions.
67 changes: 36 additions & 31 deletions project/Build.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,19 @@ import xerial.sbt.Sonatype.autoImport._
* The release process is customised to include a step to run ''dependencyCheck''.
*/
object Build extends BuildDef with BuildCommon {
import BuildSettings._

private val schemaVersions = Seq("3.3", "3.4", "3.5", "3.6")

lazy val mainProjects: Seq[Project] = schemaVersions.map(nitfProject)
lazy val testProjects: Seq[Project] = schemaVersions.map(testProject)
lazy val realProjects: Seq[Project] = mainProjects ++ testProjects
lazy val leafProjects: Seq[Project] = mainProjects ++ testProjects

override def projects: Seq[Project] = rootProject.toSeq ++ leafProjects

override def projects: Seq[Project] = rootProject.toSeq ++ realProjects
override def rootProject = Some(
Project(id = Metadata.projectName, base = file("."))
.aggregate(realProjects.map(Project.projectToRef): _*)
.aggregate(leafProjects.map(Project.projectToRef): _*)
.settings(commonSettings ++ disabledPublishingSettings)
.settings(
crossScalaVersions := Dependencies.scalaVersions,
Expand All @@ -35,34 +38,55 @@ object Build extends BuildDef with BuildCommon {
)
)

private lazy val commonSettings = Metadata.settings ++ Seq(
private def nitfProject(schemaVersion: String): Project = {
Project(id = projectId(schemaVersion), base = file(schemaVersion))
.settings(mainSettings)
.settings(version := s"$schemaVersion.${(ThisBuild/version).value}")
}

private def testProject(schemaVersion: String): Project = {
val mainProjectId = projectId(schemaVersion)
Project(id = mainProjectId + "Test", base = file("Tests"))
.settings(testSettings)
.settings(
target := baseDirectory.value / s"target/$schemaVersion",
javaOptions += s"-Dnitf.schema.version=$schemaVersion"
)
.dependsOn(mainProjects.find(_.id == mainProjectId).get)
}

private def projectId(schemaVersion: String) = "nitf" + schemaVersion.replaceAll("""\.""", "")
}

object BuildSettings {
val commonDependencies: Seq[ModuleID] = Dependencies.xmlParsing

val commonSettings: Seq[Setting[_]] = Metadata.settings ++ Seq(
crossScalaVersions := Dependencies.scalaVersions,
scalaVersion := Dependencies.scalaVersions.min,
scalacOptions += "-target:jvm-1.8",

dependencyCheckFailBuildOnCVSS := 4
)

private val commonDependencies = Dependencies.xmlParsing
val disabledPublishingSettings: Seq[Setting[_]] = Seq(
skip in publish := true
)

private lazy val mainSettings = commonSettings ++ Seq(
val mainSettings: Seq[Setting[_]] = commonSettings ++ Seq(
name := "nitf-scala",
publishTo := sonatypePublishTo.value,
libraryDependencies ++= commonDependencies
)

private lazy val testSettings = commonSettings ++ disabledPublishingSettings ++ Seq(
val testSettings: Seq[Setting[_]] = commonSettings ++ disabledPublishingSettings ++ Seq(
fork := true,
libraryDependencies ++= commonDependencies ++ Dependencies.testing,
dependencyCheckSkip := true
)

val disabledPublishingSettings: Seq[Setting[_]] = Seq(
skip in publish := true
)

val releasePublishAction: TaskKey[_] = PgpKeys.publishSigned
private val releasingProcess = Seq[ReleaseStep](ReleaseStep(identity) /* no-op */
val releasingProcess: Seq[ReleaseStep] = Seq(ReleaseStep(identity) /* no-op */
, runClean
, checkSnapshotDependencies
, releaseStepTask(dependencyCheckAggregate)
Expand All @@ -76,23 +100,4 @@ object Build extends BuildDef with BuildCommon {
, commitNextVersion
, pushChanges
)

private def nitfProject(schemaVersion: String): Project = {
Project(id = projectId(schemaVersion), base = file(schemaVersion))
.settings(mainSettings)
.settings(version := s"$schemaVersion.${(ThisBuild/version).value}")
}

private def testProject(schemaVersion: String): Project = {
val mainProjectId = projectId(schemaVersion)
Project(id = mainProjectId + "Test", base = file("Tests"))
.settings(testSettings)
.settings(
target := baseDirectory.value / s"target/$schemaVersion",
javaOptions += s"-Dnitf.schema.version=$schemaVersion"
)
.dependsOn(mainProjects.find(_.id == mainProjectId).get)
}

private def projectId(schemaVersion: String) = "nitf" + schemaVersion.replaceAll("""\.""", "")
}

0 comments on commit 8b475db

Please sign in to comment.