|
| 1 | +import com.typesafe.sbt.SbtGit.GitCommand |
| 2 | +import sbt.Keys._ |
| 3 | +import sbt._ |
| 4 | +import sbtassembly.AssemblyKeys.assembly |
| 5 | +import sbtassembly.MergeStrategy |
| 6 | +import sbtrelease.ReleasePlugin.autoImport.ReleaseTransformations._ |
| 7 | +import scoverage.ScoverageKeys._ |
| 8 | + |
| 9 | +//////////////////////////////////////////////////////////////////////////////////////////////// |
| 10 | +// We have the following "settings" in this build.sbt: |
| 11 | +// - versioning with sbt-release |
| 12 | +// - custom JAR name for the root project |
| 13 | +// - settings to publish to Sonatype |
| 14 | +// - exclude the root, tasks, and pipelines project from code coverage |
| 15 | +// - scaladoc settings |
| 16 | +// - custom merge strategy for assembly |
| 17 | +//////////////////////////////////////////////////////////////////////////////////////////////// |
| 18 | + |
| 19 | +//////////////////////////////////////////////////////////////////////////////////////////////// |
| 20 | +// Use sbt-release to bump the version numbers. |
| 21 | +// |
| 22 | +// see: http://blog.byjean.eu/2015/07/10/painless-release-with-sbt.html |
| 23 | +//////////////////////////////////////////////////////////////////////////////////////////////// |
| 24 | + |
| 25 | +// Release settings |
| 26 | +releaseVersionBump := sbtrelease.Version.Bump.Next |
| 27 | +releasePublishArtifactsAction := PgpKeys.publishSigned.value |
| 28 | +releaseProcess := Seq[ReleaseStep]( |
| 29 | + checkSnapshotDependencies, |
| 30 | + inquireVersions, |
| 31 | + runClean, |
| 32 | + runTest, |
| 33 | + setReleaseVersion, |
| 34 | + commitReleaseVersion, |
| 35 | + tagRelease, |
| 36 | + ReleaseStep(action = Command.process("publishSigned", _)), |
| 37 | + setNextVersion, |
| 38 | + commitNextVersion, |
| 39 | + ReleaseStep(action = Command.process("sonatypeReleaseAll", _)), |
| 40 | + pushChanges |
| 41 | +) |
| 42 | + |
| 43 | +//////////////////////////////////////////////////////////////////////////////////////////////// |
| 44 | +// For the aggregate (root) jar, override the name. For the sub-projects, |
| 45 | +// see the build.sbt in each project folder. |
| 46 | +//////////////////////////////////////////////////////////////////////////////////////////////// |
| 47 | +assemblyJarName in assembly := "commons-" + version.value + ".jar" |
| 48 | + |
| 49 | +//////////////////////////////////////////////////////////////////////////////////////////////// |
| 50 | +// Sonatype settings |
| 51 | +//////////////////////////////////////////////////////////////////////////////////////////////// |
| 52 | +publishMavenStyle := true |
| 53 | +publishTo := { |
| 54 | + val nexus = "https://oss.sonatype.org/" |
| 55 | + if (isSnapshot.value) |
| 56 | + Some("snapshots" at nexus + "content/repositories/snapshots") |
| 57 | + else |
| 58 | + Some("releases" at nexus + "service/local/staging/deploy/maven2") |
| 59 | +} |
| 60 | +publishArtifact in Test := false |
| 61 | +pomIncludeRepository := { _ => false } |
| 62 | +// For Travis CI - see http://www.cakesolutions.net/teamblogs/publishing-artefacts-to-oss-sonatype-nexus-using-sbt-and-travis-ci |
| 63 | +credentials ++= (for { |
| 64 | + username <- Option(System.getenv().get("SONATYPE_USER")) |
| 65 | + password <- Option(System.getenv().get("SONATYPE_PASS")) |
| 66 | +} yield Credentials("Sonatype Nexus Repository Manager", "oss.sonatype.org", username, password)).toSeq |
| 67 | + |
| 68 | +//////////////////////////////////////////////////////////////////////////////////////////////// |
| 69 | +// Coverage settings: include all sources |
| 70 | +//////////////////////////////////////////////////////////////////////////////////////////////// |
| 71 | +val htmlReportsDirectory: String = "target/test-reports" |
| 72 | + |
| 73 | +//////////////////////////////////////////////////////////////////////////////////////////////// |
| 74 | +// scaladoc options |
| 75 | +//////////////////////////////////////////////////////////////////////////////////////////////// |
| 76 | +val docScalacOptions = Seq("-groups", "-implicits") |
| 77 | + |
| 78 | +//////////////////////////////////////////////////////////////////////////////////////////////// |
| 79 | +// Common settings for all projects |
| 80 | +//////////////////////////////////////////////////////////////////////////////////////////////// |
| 81 | + |
| 82 | +lazy val commonSettings = Seq( |
| 83 | + organization := "com.fulcrumgenomics", |
| 84 | + organizationName := "Fulcrum Genomics LLC", |
| 85 | + organizationHomepage := Some(url("http://www.fulcrumgenomics.com")), |
| 86 | + homepage := Some(url("http://github.com/fulcrumgenomics/commons")), |
| 87 | + startYear := Some(2015), |
| 88 | + scalaVersion := "2.11.8", |
| 89 | + crossScalaVersions := Seq("2.11.8", "2.12.1"), |
| 90 | + scalacOptions += "-target:jvm-1.8", |
| 91 | + scalacOptions in (Compile, doc) ++= docScalacOptions, |
| 92 | + scalacOptions in (Test, doc) ++= docScalacOptions, |
| 93 | + autoAPIMappings := true, |
| 94 | + testOptions in Test += Tests.Argument(TestFrameworks.ScalaTest, "-h", Option(System.getenv("TEST_HTML_REPORTS")).getOrElse(htmlReportsDirectory)), |
| 95 | + testOptions in Test += Tests.Argument("-l", "LongRunningTest"), // ignores long running tests |
| 96 | + // uncomment for full stack traces |
| 97 | + //testOptions in Test += Tests.Argument("-oD"), |
| 98 | + fork in Test := true, |
| 99 | + resolvers += Resolver.jcenterRepo, |
| 100 | + shellPrompt := { state => "%s| %s> ".format(GitCommand.prompt.apply(state), version.value) }, |
| 101 | + updateOptions := updateOptions.value.withCachedResolution(true) |
| 102 | +) ++ Defaults.coreDefaultSettings |
| 103 | + |
| 104 | +//////////////////////////////////////////////////////////////////////////////////////////////// |
| 105 | +// commons project |
| 106 | +//////////////////////////////////////////////////////////////////////////////////////////////// |
| 107 | +lazy val assemblySettings = Seq( |
| 108 | + test in assembly := {}, |
| 109 | + logLevel in assembly := Level.Info |
| 110 | +) |
| 111 | +lazy val root = Project(id="commons", base=file(".")) |
| 112 | + .settings(commonSettings: _*) |
| 113 | + .settings(unidocSettings: _*) |
| 114 | + .settings(assemblySettings: _*) |
| 115 | + .settings(description := "Scala commons for Fulcrum Genomics.") |
| 116 | + .settings( |
| 117 | + libraryDependencies ++= Seq( |
| 118 | + "org.scala-lang" % "scala-reflect" % scalaVersion.value, |
| 119 | + |
| 120 | + //---------- Test libraries -------------------// |
| 121 | + "org.scalatest" %% "scalatest" % "3.0.1" % "test->*" excludeAll ExclusionRule(organization="org.junit", name="junit") |
| 122 | + ) |
| 123 | + ) |
| 124 | + |
| 125 | +//////////////////////////////////////////////////////////////////////////////////////////////// |
| 126 | +// Merge strategy for assembly |
| 127 | +//////////////////////////////////////////////////////////////////////////////////////////////// |
| 128 | +val customMergeStrategy: String => MergeStrategy = { |
| 129 | + case x if Assembly.isConfigFile(x) => |
| 130 | + MergeStrategy.concat |
| 131 | + case PathList(ps@_*) if Assembly.isReadme(ps.last) || Assembly.isLicenseFile(ps.last) => |
| 132 | + MergeStrategy.rename |
| 133 | + case PathList("META-INF", xs@_*) => |
| 134 | + xs map { |
| 135 | + _.toLowerCase |
| 136 | + } match { |
| 137 | + case ("manifest.mf" :: Nil) | ("index.list" :: Nil) | ("dependencies" :: Nil) => |
| 138 | + MergeStrategy.discard |
| 139 | + case ps@(x :: xt) if ps.last.endsWith(".sf") || ps.last.endsWith(".dsa") => |
| 140 | + MergeStrategy.discard |
| 141 | + case "plexus" :: xt => |
| 142 | + MergeStrategy.discard |
| 143 | + case "spring.tooling" :: xt => |
| 144 | + MergeStrategy.discard |
| 145 | + case "com.google.guava" :: xt => |
| 146 | + MergeStrategy.discard |
| 147 | + case "services" :: xt => |
| 148 | + MergeStrategy.filterDistinctLines |
| 149 | + case ("spring.schemas" :: Nil) | ("spring.handlers" :: Nil) => |
| 150 | + MergeStrategy.filterDistinctLines |
| 151 | + case _ => MergeStrategy.deduplicate |
| 152 | + } |
| 153 | + case "asm-license.txt" | "overview.html" => |
| 154 | + MergeStrategy.discard |
| 155 | + case "logback.xml" => |
| 156 | + MergeStrategy.first |
| 157 | + case _ => MergeStrategy.deduplicate |
| 158 | +} |
| 159 | +assemblyMergeStrategy in assembly := customMergeStrategy |
0 commit comments