diff options
-rw-r--r-- | .gitignore | 3 | ||||
-rw-r--r-- | build.sbt | 17 | ||||
-rw-r--r-- | project/DriverConfigurations.scala | 105 | ||||
-rw-r--r-- | project/plugins.sbt | 4 | ||||
-rw-r--r-- | version.sbt | 1 |
5 files changed, 116 insertions, 14 deletions
@@ -15,4 +15,5 @@ project/plugins/project/ # Scala-IDE specific .scala_dependencies .worksheet -.idea/
\ No newline at end of file +.idea/ +.idea
\ No newline at end of file @@ -1,19 +1,8 @@ import sbt._ import Keys._ +import DriverConfigurations._ -lazy val wartRemoverSettings = Seq( - wartremoverErrors in (Compile, compile) ++= Warts.allBut( - Wart.AsInstanceOf, Wart.Nothing, Wart.Option2Iterable, Wart.ExplicitImplicitTypes, - Wart.Overloading, Wart.DefaultArguments, Wart.ToString, Wart.Any, Wart.Throw) -) - -lazy val scalafmtSettings = Seq( - scalafmtConfig in ThisBuild := Some(file(".scalafmt")), - testExecution in (Test, test) <<= - (testExecution in (Test, test)) dependsOn (scalafmtTest in Compile, scalafmtTest in Test) -) - lazy val compileScalastyle = taskKey[Unit]("compileScalastyle") lazy val buildSettings = Defaults.coreDefaultSettings ++ Seq ( @@ -27,7 +16,7 @@ lazy val buildSettings = Defaults.coreDefaultSettings ++ Seq ( fork in run := true, compileScalastyle := (scalastyle in Compile).toTask("").value, (compile in Compile) <<= ((compile in Compile) dependsOn compileScalastyle) -) ++ wartRemoverSettings ++ scalafmtSettings +) ++ wartRemoverSettings ++ DriverConfigurations.scalafmtSettings lazy val akkaHttpV = "2.4.8" @@ -51,3 +40,5 @@ lazy val core = (project in file(".")). "com.github.swagger-akka-http" %% "swagger-akka-http" % "0.7.1", "com.lihaoyi" %% "acyclic" % "0.1.4" % "provided" )) + .gitPluginConfiguration + .settings(publicationSettings() ++ releaseSettings()) diff --git a/project/DriverConfigurations.scala b/project/DriverConfigurations.scala new file mode 100644 index 0000000..097279a --- /dev/null +++ b/project/DriverConfigurations.scala @@ -0,0 +1,105 @@ +import org.scalafmt.sbt.ScalaFmtPlugin.autoImport._ +import sbt.Keys._ +import sbt._ +import wartremover.WartRemover.autoImport._ +import com.typesafe.sbt.SbtGit.git +import com.typesafe.sbt.{GitBranchPrompt, GitVersioning} +import org.scalafmt.sbt.ScalaFmtPlugin.autoImport._ +import sbtrelease.{Version, _} +// we hide the existing definition for setReleaseVersion to replace it with our own +import sbtrelease.ReleasePlugin.autoImport.ReleaseTransformations._ +import sbtrelease.ReleasePlugin.autoImport._ +import sbtrelease.ReleaseStateTransformations.{setReleaseVersion => _} + + +object DriverConfigurations { + + lazy val wartRemoverSettings = Seq( + wartremoverErrors in (Compile, compile) ++= Warts.allBut( + Wart.AsInstanceOf, Wart.Nothing, Wart.Overloading, Wart.DefaultArguments, Wart.Any, + Wart.Option2Iterable, Wart.ExplicitImplicitTypes, Wart.Throw, Wart.ToString) + ) + + lazy val acyclicSettings = Seq( + autoCompilerPlugins := true, + addCompilerPlugin("com.lihaoyi" %% "acyclic" % "0.1.4") + ) + + lazy val scalafmtSettings = Seq( + scalafmtConfig in ThisBuild := Some(file(".scalafmt")), + testExecution in (Test, test) <<= + (testExecution in (Test, test)) dependsOn (scalafmtTest in Compile, scalafmtTest in Test) + ) + + lazy val compileScalastyle = taskKey[Unit]("compileScalastyle") + + def publicationSettings() = Seq( + publishTo := Some(Resolver.file("file", new File("releases"))) + // publishTo := { // TODO: For actual Driver jar repo + // val nexus = "https://my.artifact.repo.net/" + // if (isSnapshot.value) + // Some("snapshots" at nexus + "content/repositories/snapshots") + // else + // Some("releases" at nexus + "service/local/staging/deploy/maven2") + // } + ) + + def releaseSettings() = { + def setVersionOnly(selectVersion: Versions => String): ReleaseStep = { st: State => + val vs = st.get(ReleaseKeys.versions).getOrElse( + sys.error("No versions are set! Was this release part executed before inquireVersions?")) + val selected = selectVersion(vs) + + st.log.info("Setting version to '%s'." format selected) + val useGlobal = Project.extract(st).get(releaseUseGlobalVersion) + + reapply(Seq( + if (useGlobal) version in ThisBuild := selected else version := selected + ), st) + } + + lazy val setReleaseVersion: ReleaseStep = setVersionOnly(_._1) + + Seq( + releaseIgnoreUntrackedFiles := true, + // Check http://blog.byjean.eu/2015/07/10/painless-release-with-sbt.html for details + releaseVersionBump := sbtrelease.Version.Bump.Minor, + releaseVersion <<= releaseVersionBump(bumper => { + ver => Version(ver) + .map(_.withoutQualifier) + .map(_.bump(bumper).string).getOrElse(versionFormatError) + }), + releaseProcess := Seq[ReleaseStep]( + checkSnapshotDependencies, + inquireVersions, + runTest, // probably, runTest after setReleaseVersion, if tests depend on version + setReleaseVersion, + commitReleaseVersion, // performs the initial git checks + tagRelease, + publishArtifacts, + setNextVersion, + commitNextVersion, + pushChanges // also checks that an upstream branch is properly configured + ) + ) + } + + implicit class driverConfigurations(project: Project) { + + def gitPluginConfiguration: Project = { + val VersionRegex = "v([0-9]+.[0-9]+.[0-9]+)-?(.*)?".r + + project + .enablePlugins(GitVersioning, GitBranchPrompt) + .settings( + git.useGitDescribe := true, + git.baseVersion := "0.0.0", + git.gitTagToVersionNumber := { + case VersionRegex(v, "SNAPSHOT") => Some(s"$v-SNAPSHOT") + case VersionRegex(v, "") => Some(v) + case VersionRegex(v, s) => Some(s"$v-$s-SNAPSHOT") + case _ => None + }) + } + } +}
\ No newline at end of file diff --git a/project/plugins.sbt b/project/plugins.sbt index ee760ea..a3a7fb7 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -3,5 +3,9 @@ addSbtPlugin("com.geirsson" % "sbt-scalafmt" % "0.2.10") addSbtPlugin("org.wartremover" % "sbt-wartremover" % "1.0.1") addSbtPlugin("org.scalastyle" %% "scalastyle-sbt-plugin" % "0.8.0") +// Launch and deploy/release plugins +addSbtPlugin("com.typesafe.sbt" % "sbt-git" % "0.8.5") +addSbtPlugin("com.github.gseitz" % "sbt-release" % "1.0.3") + // This plugin represents functionality that is to be added to sbt in the future addSbtPlugin("org.scala-sbt" % "sbt-core-next" % "0.1.1")
\ No newline at end of file diff --git a/version.sbt b/version.sbt new file mode 100644 index 0000000..1540682 --- /dev/null +++ b/version.sbt @@ -0,0 +1 @@ +version in ThisBuild := "0.1-SNAPSHOT" |