scalafx-utils/project/Build.scala

342 lines
12 KiB
Scala
Raw Normal View History

2015-04-15 04:25:04 +00:00
import sbt._
import Keys._
2016-05-05 03:59:15 +00:00
import com.typesafe.sbt.site._
2015-08-18 20:45:29 +00:00
import sbtrelease.ReleasePlugin.autoImport._
import com.typesafe.sbt.SbtPgp.autoImport._
2015-04-15 04:25:04 +00:00
import scala.util.Properties.envOrNone
import com.typesafe.sbteclipse.plugin.EclipsePlugin._
import Helpers._
sealed trait Basics {
2015-08-11 19:35:25 +00:00
final val buildOrganization = "org.gerweck.scalafx"
final val buildOrganizationName = "Sarah Gerweck"
final val buildOrganizationUrl = Some("https://github.com/sarahgerweck")
2015-04-15 04:25:04 +00:00
2016-04-17 03:47:06 +00:00
final val buildScalaVersion = "2.11.8"
2015-08-11 19:35:25 +00:00
final val extraScalaVersions = Seq.empty
2015-08-18 20:45:29 +00:00
final val minimumJavaVersion = "1.8"
2015-08-11 19:35:25 +00:00
lazy val defaultOptimize = true
final val projectMainClass = None
2015-04-15 04:25:04 +00:00
2015-08-11 19:35:25 +00:00
lazy val parallelBuild = false
2015-08-18 20:45:29 +00:00
lazy val cachedResolution = true
2015-04-15 04:25:04 +00:00
/* Metadata definitions */
lazy val buildMetadata = Vector(
licenses := Seq("Apache License, Version 2.0" -> url("http://www.apache.org/licenses/LICENSE-2.0.txt")),
2015-04-15 06:30:11 +00:00
homepage := Some(url("https://github.com/sarahgerweck/scalafx-utils")),
2015-04-15 04:25:04 +00:00
description := "ScalaFX Utilities",
startYear := Some(2015),
2015-04-15 06:30:11 +00:00
scmInfo := Some(ScmInfo(url("https://github.com/sarahgerweck/scalafx-utils"), "scm:git:git@github.com:sarahgerweck/scalafx-utils.git"))
2015-04-15 04:25:04 +00:00
)
2015-08-18 20:45:29 +00:00
lazy val developerInfo = {
<developers>
<developer>
<id>sarah</id>
<name>Sarah Gerweck</name>
<email>sarah.a180@gmail.com</email>
<url>https://github.com/sarahgerweck</url>
<timezone>America/Los_Angeles</timezone>
</developer>
</developers>
}
2015-04-15 04:25:04 +00:00
}
object BuildSettings extends Basics {
/* Overridable flags */
lazy val optimize = boolFlag("OPTIMIZE") orElse boolFlag("OPTIMISE") getOrElse defaultOptimize
lazy val deprecation = boolFlag("NO_DEPRECATION") map (!_) getOrElse true
lazy val inlineWarn = boolFlag("INLINE_WARNINGS") getOrElse false
lazy val debug = boolFlag("DEBUGGER") getOrElse false
lazy val debugPort = envOrNone("DEBUGGER_PORT") map { _.toInt } getOrElse 5050
lazy val debugSuspend = boolFlag("DEBUGGER_SUSPEND") getOrElse true
lazy val unusedWarn = boolFlag("UNUSED_WARNINGS") getOrElse false
lazy val importWarn = boolFlag("IMPORT_WARNINGS") getOrElse false
lazy val buildScalaVersions = buildScalaVersion +: extraScalaVersions
val buildScalacOptions = Seq (
"-unchecked",
"-feature",
2015-08-18 20:45:29 +00:00
"-target:jvm-" + minimumJavaVersion
2015-04-15 04:25:04 +00:00
) ++ (
if (deprecation) Seq("-deprecation") else Seq.empty
) ++ (
if (optimize) Seq("-optimize") else Seq.empty
) ++ (
if (inlineWarn) Seq("-Yinline-warnings") else Seq.empty
) ++ (
if (unusedWarn) Seq("-Ywarn-unused") else Seq.empty
) ++ (
if (importWarn) Seq("-Ywarn-unused-import") else Seq.empty
)
/* Java build setup */
val buildJavacOptions = Seq(
2015-08-18 20:45:29 +00:00
"-target", minimumJavaVersion,
"-source", minimumJavaVersion
2015-04-15 04:25:04 +00:00
) ++ (
if (deprecation) Seq("-Xlint:deprecation") else Seq.empty
)
2016-05-05 03:59:15 +00:00
/** A wrapper so we can call `commonSettings()` on a project. */
implicit class ProjectSettingsHelper(p: Project) {
def commonSettings() = siteSettings(p).settings(buildSettings: _*)
2015-04-15 04:25:04 +00:00
2016-05-05 03:59:15 +00:00
private[this] def siteSettings(p: Project) = p.enablePlugins(SiteScaladocPlugin)
2015-04-15 04:25:04 +00:00
2016-05-05 03:59:15 +00:00
private[this] val buildSettings = buildMetadata ++
projectMainClass.toSeq.map(mainClass := Some(_)) ++
Seq (
organization := buildOrganization,
organizationName := buildOrganizationName,
organizationHomepage := buildOrganizationUrl map { url _ },
2015-04-15 04:25:04 +00:00
2016-05-05 03:59:15 +00:00
scalaVersion := buildScalaVersion,
crossScalaVersions := buildScalaVersions,
2015-04-15 04:25:04 +00:00
2016-05-05 03:59:15 +00:00
scalacOptions ++= buildScalacOptions,
javacOptions ++= buildJavacOptions,
autoAPIMappings := true,
2015-04-15 04:25:04 +00:00
2016-05-05 03:59:15 +00:00
updateOptions := updateOptions.value.withCachedResolution(cachedResolution),
parallelExecution := parallelBuild,
evictionWarningOptions in update :=
EvictionWarningOptions.default.withWarnTransitiveEvictions(false).withWarnDirectEvictions(false).withWarnScalaVersionEviction(false)
)
}
2015-04-15 04:25:04 +00:00
}
object Helpers {
def getProp(name: String): Option[String] = sys.props.get(name) orElse sys.env.get(name)
def parseBool(str: String): Boolean = Set("yes", "y", "true", "t", "1") contains str.trim.toLowerCase
def boolFlag(name: String): Option[Boolean] = getProp(name) map { parseBool _ }
def boolFlag(name: String, default: Boolean): Boolean = boolFlag(name) getOrElse default
def opts(names: String*): Option[String] = names.view.map(getProp _).foldLeft(None: Option[String]) { _ orElse _ }
import scala.xml._
def excludePomDeps(exclude: (String, String) => Boolean): Node => Node = { node: Node =>
val rewriteRule = new transform.RewriteRule {
override def transform(n: Node): NodeSeq = {
if ((n.label == "dependency") && exclude((n \ "groupId").text, (n \ "artifactId").text))
NodeSeq.Empty
else
n
}
}
val transformer = new transform.RuleTransformer(rewriteRule)
transformer.transform(node)(0)
}
}
object Resolvers {
val sonatypeSnaps = Resolver.sonatypeRepo("snapshots")
val sonatypeRelease = Resolver.sonatypeRepo("releases")
val sonatypeStaging = "Sonatype Staging" at "https://oss.sonatype.org/service/local/staging/deploy/maven2"
2015-04-15 04:25:04 +00:00
}
2015-08-18 20:45:29 +00:00
object Publish {
2015-04-15 04:25:04 +00:00
import BuildSettings._
import Resolvers._
import Helpers._
val sonaCreds = (
for {
user <- getProp("SONATYPE_USER")
pass <- getProp("SONATYPE_PASS")
} yield {
credentials +=
Credentials("Sonatype Nexus Repository Manager",
"oss.sonatype.org",
user, pass)
}
).toSeq
2015-08-18 20:45:29 +00:00
val settings = sonaCreds ++ Seq (
2015-04-15 04:25:04 +00:00
publishMavenStyle := true,
pomIncludeRepository := { _ => false },
publishArtifact in Test := false,
publishTo := {
if (version.value.trim endsWith "SNAPSHOT")
Some(sonatypeSnaps)
else
Some(sonatypeStaging)
},
2015-08-18 20:45:29 +00:00
pomExtra := developerInfo
2015-04-15 04:25:04 +00:00
)
/** Use this if you don't want to publish a certain module.
* (SBT's release plugin doesn't handle this well.)
*/
2015-08-18 20:45:29 +00:00
val falseSettings = settings ++ Seq (
2015-04-15 04:25:04 +00:00
publishArtifact in Compile := false,
publishArtifact in Test := false,
publishTo := Some(Resolver.file("phony-repo", file("target/repo")))
)
}
object Release {
2015-08-15 09:37:39 +00:00
val settings = Seq (
releaseCrossBuild := true,
releasePublishArtifactsAction := PgpKeys.publishSigned.value
)
2015-04-15 04:25:04 +00:00
}
object Eclipse {
import com.typesafe.sbteclipse.plugin.EclipsePlugin._
val settings = Seq (
EclipseKeys.createSrc := EclipseCreateSrc.Default + EclipseCreateSrc.Resource,
EclipseKeys.projectFlavor := EclipseProjectFlavor.Scala,
2015-08-10 05:32:35 +00:00
EclipseKeys.executionEnvironment := Some(EclipseExecutionEnvironment.JavaSE18),
EclipseKeys.withSource := true,
EclipseKeys.eclipseOutput := Some("target/scala-2.11/classes")
2015-04-15 04:25:04 +00:00
)
}
object Dependencies {
2016-04-19 04:14:03 +00:00
/* ********************************************************************** */
/* Akka */
/* ********************************************************************** */
2016-05-29 23:01:06 +00:00
final val akkaVersion = "2.4.6"
2016-04-19 04:14:03 +00:00
val akkaActor = "com.typesafe.akka" %% "akka-actor" % akkaVersion
val akkaAgent = "com.typesafe.akka" %% "akka-agent" % akkaVersion
val akkaStream = "com.typesafe.akka" %% "akka-stream" % akkaVersion
2015-04-15 04:25:04 +00:00
/* ********************************************************************** */
/* Utility Dependencies */
/* ********************************************************************** */
2016-04-17 03:47:06 +00:00
final val slf4jVersion = "1.7.21"
final val log4sVersion = "1.3.0"
final val logbackVersion = "1.1.7"
2015-04-15 04:25:04 +00:00
final val commonsVfsVersion = "2.0"
final val commonsIoVersion = "2.4"
2016-05-29 23:01:06 +00:00
final val spireVersion = "0.11.0"
2015-08-09 18:34:13 +00:00
final val groovyVersion = "2.4.4"
2015-05-02 02:25:46 +00:00
final val scalaParserVersion = "1.0.4"
2015-08-09 18:34:13 +00:00
final val scalaXmlVersion = "1.0.5"
2016-05-29 23:01:06 +00:00
final val gerweckUtilVersion = "1.7.1"
final val scalazVersion = "7.2.3"
final val shapelessVersion = "2.3.1"
final val scallopVersion = "1.0.1"
2015-04-15 04:25:04 +00:00
2015-08-16 00:22:24 +00:00
val log4s = "org.log4s" %% "log4s" % log4sVersion
val slf4j = "org.slf4j" % "slf4j-api" % slf4jVersion
val jclBridge = "org.slf4j" % "jcl-over-slf4j" % slf4jVersion
val log4jBridge = "org.slf4j" % "log4j-over-slf4j" % slf4jVersion
val logback = "ch.qos.logback" % "logback-classic" % logbackVersion
val spire = "org.spire-math" %% "spire" % spireVersion
val commonsIo = "commons-io" % "commons-io" % commonsIoVersion
val groovy = "org.codehaus.groovy" % "groovy-all" % groovyVersion
val gerweckUtil = "org.gerweck.scala" %% "gerweck-utils-java8" % gerweckUtilVersion
val scalaz = "org.scalaz" %% "scalaz-core" % scalazVersion
val shapeless = "com.chuusai" %% "shapeless" % shapelessVersion
val scallop = "org.rogach" %% "scallop" % scallopVersion
2015-04-15 04:25:04 +00:00
val commonsVfs = {
val base = "org.apache.commons" % "commons-vfs2" % commonsVfsVersion
base.exclude("commons-logging", "commons-logging")
.exclude("org.apache.maven.scm", "maven-scm-provider-svnexe")
.exclude("org.apache.maven.scm", "maven-scm-api")
base
}
/* Use like this: libraryDependencies <++= (scalaBinaryVersion) (scalaParser) */
def scalaParser(optional: Boolean): String => Seq[ModuleID] = { scalaBinaryVersion: String =>
optionalize(optional) {
scalaBinaryVersion match {
case "2.11" => Seq("org.scala-lang.modules" %% "scala-parser-combinators" % scalaParserVersion % "optional")
case _ => Seq.empty
}
}
}
def scalaXml(optional: Boolean)(scalaBinaryVersion: String): String => Seq[ModuleID] = { scalaBinaryVersion: String =>
optionalize(optional) {
scalaBinaryVersion match {
case "2.11" => Seq("org.scala-lang.modules" %% "scala-xml" % scalaXmlVersion % "optional")
case _ => Seq.empty
}
}
}
/* ********************************************************************** */
/* Testing Dependencies */
/* ********************************************************************** */
final val scalaCheckVersion = "1.12.2"
final val scalaTestVersion = "2.2.4"
val scalaCheck = "org.scalacheck" %% "scalacheck" % scalaCheckVersion
val scalaTest = "org.scalatest" %% "scalatest" % scalaTestVersion
2015-04-15 04:45:24 +00:00
/* ********************************************************************** */
/* ScalaFX */
/* ********************************************************************** */
final val scalaFxVersion = "8.0.92-R10"
2015-04-15 04:45:24 +00:00
val scalaFx = "org.scalafx" %% "scalafx" % scalaFxVersion
2015-04-15 04:44:51 +00:00
/* ********************************************************************** */
/* Helpers */
/* ********************************************************************** */
2015-04-15 04:25:04 +00:00
private[this] def optionalize(optional: Boolean)(f: => Seq[ModuleID]): Seq[ModuleID] = {
if (optional) {
f map { _ % "optional" }
} else {
f
}
}
private[this] def noCL(m: ModuleID) = (
m exclude("commons-logging", "commons-logging")
exclude("commons-logging", "commons-logging-api")
)
}
object UtilsBuild extends Build {
build =>
import BuildSettings._
import Resolvers._
import Dependencies._
import Helpers._
lazy val root = (project in file ("."))
2016-05-05 03:59:15 +00:00
.commonSettings()
2015-04-15 04:25:04 +00:00
.settings(Eclipse.settings: _*)
2015-08-18 20:45:29 +00:00
.settings(Publish.settings: _*)
2015-04-15 04:25:04 +00:00
.settings(Release.settings: _*)
.settings(resolvers += sonatypeRelease)
2015-04-15 04:25:04 +00:00
.settings(
name := "ScalaFX Utils",
libraryDependencies ++= Seq (
log4s,
slf4j,
jclBridge % "runtime,optional",
log4jBridge % "runtime,optional",
logback % "runtime,optional",
2015-04-15 04:45:24 +00:00
gerweckUtil,
2015-04-15 04:50:39 +00:00
scalaFx,
2015-04-16 20:24:21 +00:00
scalaz,
shapeless
2015-04-15 04:25:04 +00:00
),
2016-04-19 04:14:03 +00:00
/* Akka dependencies */
libraryDependencies ++= Seq (
akkaActor % "optional",
akkaStream % "optional",
akkaAgent % "optional"
),
2015-04-15 04:50:39 +00:00
unmanagedJars in Compile += Attributed.blank(file(System.getenv("JAVA_HOME") + "/jre/lib/ext/jfxrt.jar"))
2015-04-15 04:25:04 +00:00
)
}