-
Notifications
You must be signed in to change notification settings - Fork 84
/
CommonSettings.scala
181 lines (164 loc) · 5.97 KB
/
CommonSettings.scala
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
// these two imports are needed for sbt syntax to work
import com.typesafe.sbt.SbtNativePackager.{Docker, Windows}
import com.typesafe.sbt.SbtNativePackager.autoImport.packageName
import java.nio.file.Paths
import com.typesafe.sbt.packager.Keys.{daemonUser, daemonUserUid, dockerAlias, dockerAliases, dockerRepository, dockerUpdateLatest, maintainer}
import com.typesafe.sbt.packager.docker.DockerPlugin.autoImport.dockerBaseImage
import sbt._
import sbt.Keys._
import sbtprotoc.ProtocPlugin.autoImport.PB
import sbtassembly.AssemblyKeys._
import sbtdynver.DynVerPlugin.autoImport.previousStableVersion
import scala.util.Properties
object CommonSettings {
private def isCI = {
Properties
.envOrNone("CI")
.isDefined
}
lazy val settings: Seq[Setting[_]] = Vector(
organization := "org.bitcoin-s",
homepage := Some(url("https://bitcoin-s.org")),
maintainer := "Chris Stewart <stewart.chris1234@gmail.com>",
developers := List(
Developer(
"christewart",
"Chris Stewart",
"stewart.chris1234@gmail.com",
url("https://twitter.com/Chris_Stewart_5")
)
),
Compile / scalacOptions ++= compilerOpts(scalaVersion = scalaVersion.value),
Test / scalacOptions ++= testCompilerOpts(scalaVersion =
scalaVersion.value),
//remove annoying import unused things in the scala console
//https://stackoverflow.com/questions/26940253/in-sbt-how-do-you-override-scalacoptions-for-console-in-all-configurations
Compile / console / scalacOptions ~= (_ filterNot (s =>
s == "-Ywarn-unused-import"
|| s == "-Ywarn-unused"
|| s == "-Xfatal-warnings"
//for 2.13 -- they use different compiler opts
|| s == "-Xlint:unused")),
//we don't want -Xfatal-warnings for publishing with publish/publishLocal either
Compile / doc / scalacOptions ~= (_ filterNot (s =>
s == "-Xfatal-warnings")),
Test / console / scalacOptions ++= (Compile / console / scalacOptions).value,
Test / scalacOptions ++= testCompilerOpts(scalaVersion.value),
licenses += ("MIT", url("http://opensource.org/licenses/MIT")),
//you need to build protoc manually to get it working on the new
//mac m1 chip. For instructions on how to do so see
//see: https://github.com/scalapb/ScalaPB/issues/1024
PB.protocExecutable := (
if (protocbridge.SystemDetector.detectedClassifier() == "osx-aarch_64")
file(
"/usr/local/bin/protoc"
) // to change if needed, this is where protobuf manual compilation put it for me
else
PB.protocExecutable.value
),
assembly / test := {}
)
lazy val jvmSettings: Seq[Setting[_]] = List(
////
// scaladoc settings
Compile / doc / scalacOptions ++= List(
"-doc-title",
"Bitcoin-S",
"-doc-version",
version.value
),
// Set apiURL to define the base URL for the Scaladocs for our library.
// This will enable clients of our library to automatically link against
// the API documentation using autoAPIMappings.
apiURL := homepage.value.map(_.toString + "/api").map(url(_)),
// scaladoc settings end
////
Compile / compile / javacOptions ++= {
//https://github.com/eclipse/jetty.project/issues/3244#issuecomment-495322586
Seq("--release", "8")
}
)
private val commonCompilerOpts = {
List(
//https://stackoverflow.com/a/43103038/967713
"-release",
"8"
)
}
/** Linting options for scalac */
private val scala2_13CompilerLinting = {
Seq(
"-Xlint:unused",
"-Xlint:adapted-args",
"-Xlint:nullary-unit",
"-Xlint:inaccessible",
"-Xlint:infer-any",
"-Xlint:missing-interpolator",
"-Xlint:eta-sam"
)
}
/** Compiler options for source code */
private val scala2_13SourceCompilerOpts = {
Seq("-Xfatal-warnings") ++ scala2_13CompilerLinting
}
private val nonScala2_13CompilerOpts = Seq(
"-Xmax-classfile-name",
"128",
"-Ywarn-unused",
"-Ywarn-unused-import"
)
//https://docs.scala-lang.org/overviews/compiler-options/index.html
def compilerOpts(scalaVersion: String): Seq[String] = {
Seq(
"-unchecked",
"-feature",
"-deprecation",
"-Ywarn-dead-code",
"-Ywarn-value-discard",
"-Ywarn-unused",
"-unchecked",
"-deprecation",
"-feature",
"-Ypatmat-exhaust-depth",
"off"
) ++ commonCompilerOpts ++ {
if (scalaVersion.startsWith("2.13")) {
scala2_13SourceCompilerOpts
} else nonScala2_13CompilerOpts
}
}
def testCompilerOpts(scalaVersion: String): Seq[String] = {
(commonCompilerOpts ++
//initialization checks: https://docs.scala-lang.org/tutorials/FAQ/initialization-order.html
Vector("-Xcheckinit") ++
compilerOpts(scalaVersion))
.filterNot(_ == "-Xfatal-warnings")
}
lazy val testSettings: Seq[Setting[_]] = Seq(
//show full stack trace (-oF) of failed tests and duration of tests (-oD)
Test / testOptions += Tests.Argument(TestFrameworks.ScalaTest, "-oDF"),
Test / logBuffered := false,
skip / publish := true
) ++ settings
lazy val prodSettings: Seq[Setting[_]] = settings
lazy val appSettings: Seq[Setting[_]] = prodSettings ++ Vector(
//gives us the 'universal' directory in build artifacts
Compile / unmanagedResourceDirectories += baseDirectory.value / "src" / "universal"
)
lazy val dockerSettings: Seq[Setting[_]] = {
Vector(
//https://sbt-native-packager.readthedocs.io/en/latest/formats/docker.html
dockerBaseImage := "openjdk:15.0.2-jdk-buster",
dockerRepository := Some("bitcoinscala"),
//set the user to be 'bitcoin-s' rather than
//the default provided by sbt native packager
//which is 'demiourgos728'
Docker / daemonUser := "bitcoin-s",
Docker / packageName := packageName.value,
Docker / version := version.value,
dockerUpdateLatest := isSnapshot.value
)
}
lazy val binariesPath =
Paths.get(Properties.userHome, ".bitcoin-s", "binaries")
}