-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathbuild.sbt
187 lines (174 loc) · 6.5 KB
/
build.sbt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
import scala.language.reflectiveCalls
// All Twitter library releases are date versioned as YY.MM.patch
val releaseVersion = "19.5.0-SNAPSHOT"
val twitterLibVersion = "22.7.0" // util version
lazy val buildSettings = Seq(
version := releaseVersion,
scalaVersion := "2.12.8",
crossScalaVersions := Seq("2.12.8"),
scalaModuleInfo := scalaModuleInfo.value.map(_.withOverrideScalaVersion(true)),
fork in Test := true,
javaOptions in Test ++= travisTestJavaOptions
)
lazy val noPublishSettings = Seq(
publish := {},
publishLocal := {},
publishArtifact := false,
// sbt-pgp's publishSigned task needs this defined even though it is not publishing.
publishTo := Some(Resolver.file("Unused transient repository", file("target/unusedrepo")))
)
def travisTestJavaOptions: Seq[String] = {
// When building on travis-ci, we want to suppress logging to error level only.
val travisBuild = sys.env.getOrElse("TRAVIS", "false").toBoolean
if (travisBuild) {
Seq(
"-DSKIP_FLAKY=true",
"-Dsbt.log.noformat=true",
// Needed to avoid cryptic EOFException crashes in forked tests
// in Travis with `sudo: false`.
// See https://github.com/sbt/sbt/issues/653
// and https://github.com/travis-ci/travis-ci/issues/3775
"-Xmx3G"
)
} else {
Seq("-DSKIP_FLAKY=true")
}
}
lazy val versions = new {
// When building on travis-ci, querying for the branch name via git commands
// will return "HEAD", because travis-ci checks out a specific sha.
val travisBranch = sys.env.getOrElse("TRAVIS_BRANCH", "")
// All Twitter library releases are date versioned as YY.MM.patch
val twLibVersion = twitterLibVersion
val junit = "4.12"
val mockito = "1.9.5"
val scalaCheck = "1.13.4"
val scalaTest = "3.0.5"
val caffeine = "2.9.3"
val scalaCheckPlus = "3.1.2.0"
val jmh = "1.21"
}
lazy val scalaCompilerOptions = scalacOptions ++= Seq(
"-deprecation",
"-encoding",
"UTF-8",
"-feature",
"-language:existentials",
"-language:higherKinds",
"-language:implicitConversions",
"-unchecked",
"-Ywarn-dead-code",
"-Ywarn-numeric-widen",
"-Xlint",
"-Ywarn-unused-import"
)
lazy val baseSettings = Seq(
libraryDependencies ++= Seq(
"com.twitter" %% "util-core" % versions.twLibVersion,
"com.twitter" %% "util-mock" % versions.twLibVersion % Test,
"org.mockito" % "mockito-core" % versions.mockito % Test,
"org.scalacheck" %% "scalacheck" % versions.scalaCheck % Test,
"org.scalatest" %% "scalatest" % versions.scalaTest % Test,
"com.github.ben-manes.caffeine" % "caffeine" % versions.caffeine,
"org.scalatestplus" %% "scalacheck-1-14" % versions.scalaCheckPlus % Test,
"junit" % "junit" % versions.junit % Test,
"org.openjdk.jmh" % "jmh-core" % versions.jmh % Test
),
resolvers ++= Seq(
Resolver.sonatypeRepo("releases"),
Resolver.sonatypeRepo("snapshots")
),
organization := "com.twitter",
scalaCompilerOptions,
javacOptions in (Compile, compile) ++= Seq(
"-source",
"1.8",
"-target",
"1.8",
"-Xlint:unchecked"),
javacOptions in doc ++= Seq("-source", "1.8"),
// -a: print stack traces for failing asserts
testOptions += Tests.Argument(TestFrameworks.JUnit, "-a", "-v"),
// broken in 2.12 due to: https://issues.scala-lang.org/browse/SI-10134
scalacOptions in (Compile, doc) ++= {
if (scalaVersion.value.startsWith("2.12")) Seq("-no-java-comments")
else Nil
}
)
lazy val publishSettings = Seq(
publishMavenStyle := true,
publishArtifact in Compile := true,
publishArtifact in Test := false,
pomIncludeRepository := { _ => false },
publishTo := {
val nexus = "https://oss.sonatype.org/"
if (isSnapshot.value)
Some("snapshots" at nexus + "content/repositories/snapshots")
else
Some("releases" at nexus + "service/local/staging/deploy/maven2")
},
licenses := Seq("Apache 2.0" -> url("https://www.apache.org/licenses/LICENSE-2.0")),
homepage := Some(url("https://github.com/twitter/stitch")),
autoAPIMappings := true,
apiURL := Some(url("https://twitter.github.io/stitch/scaladocs/")),
excludeFilter in (Compile, managedSources) := HiddenFileFilter || "BUILD",
excludeFilter in (Compile, unmanagedSources) := HiddenFileFilter || "BUILD",
excludeFilter in (Compile, managedResources) := HiddenFileFilter || "BUILD",
excludeFilter in (Compile, unmanagedResources) := HiddenFileFilter || "BUILD",
pomExtra :=
<scm>
<url>git://github.com/twitter/stitch.git</url>
<connection>scm:git://github.com/twitter/stitch.git</connection>
</scm>
<developers>
<developer>
<id>twitter</id>
<name>Twitter Inc.</name>
<url>https://www.twitter.com/</url>
</developer>
</developers>,
pomPostProcess := { (node: scala.xml.Node) =>
val rule = new scala.xml.transform.RewriteRule {
override def transform(n: scala.xml.Node): scala.xml.NodeSeq =
n.nameToString(new StringBuilder()).toString() match {
case "dependency" if (n \ "groupId").text.trim == "org.scoverage" => Nil
case _ => n
}
}
new scala.xml.transform.RuleTransformer(rule).transform(node).head
},
resourceGenerators in Compile += Def.task {
val dir = (resourceManaged in Compile).value
val file = dir / "com" / "twitter" / name.value / "build.properties"
val buildRev = scala.sys.process.Process("git" :: "rev-parse" :: "HEAD" :: Nil).!!.trim
val buildName = new java.text.SimpleDateFormat("yyyyMMdd-HHmmss").format(new java.util.Date)
val contents =
s"name=${name.value}\nversion=${version.value}\nbuild_revision=$buildRev\nbuild_name=$buildName"
IO.write(file, contents)
Seq(file)
}.taskValue,
assemblyMergeStrategy in assembly := {
case "BUILD" => MergeStrategy.discard
case other => MergeStrategy.defaultMergeStrategy(other)
}
)
lazy val core = project
.in(file("."))
.enablePlugins(ScalaUnidocPlugin)
.settings(baseSettings)
.settings(buildSettings)
.settings(noPublishSettings)
.settings(
moduleName := "stitch-core",
unidocProjectFilter in (ScalaUnidoc, unidoc) := inAnyProject,
excludeFilter in Test in unmanagedResources := "BUILD",
publishArtifact in Test := true
)
lazy val site = (project in file("docs"))
.enablePlugins(SphinxPlugin)
.settings(
Seq(sourceDirectory in Sphinx := baseDirectory.value) ++
baseSettings ++ buildSettings ++ Seq(
scalacOptions in doc ++= Seq("-doc-title", "Stitch", "-doc-version", version.value),
includeFilter in Sphinx := ("*.html" | "*.png" | "*.svg" | "*.js" | "*.css" | "*.gif" | "*.txt")
))