-
Notifications
You must be signed in to change notification settings - Fork 7
/
Settings.scala
121 lines (109 loc) · 4.7 KB
/
Settings.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
package com.exasol.spark.sbt
import sbt._
import sbt.Keys._
import sbtassembly.MergeStrategy
import sbtassembly.PathList
import sbtassembly.AssemblyPlugin.autoImport._
import scoverage.ScoverageSbtPlugin.autoImport._
import org.scalastyle.sbt.ScalastylePlugin.autoImport._
import wartremover.WartRemover.autoImport.wartremoverErrors
import com.lucidchart.sbt.scalafmt.ScalafmtCorePlugin.autoImport._
/** A list of (boilerplate) settings for build process */
object Settings {
def projectSettings(scalaVersion: SettingKey[String]): Seq[Setting[_]] =
buildSettings(scalaVersion) ++
miscSettings ++
assemblySettings ++
apiDocSettings ++
scalaStyleSettings ++
Publishing.publishSettings()
def buildSettings(scalaVersion: SettingKey[String]): Seq[Setting[_]] = Seq(
// Compiler settings
scalacOptions ++= Compilation.compilerFlagsFn(scalaVersion.value),
scalacOptions in (Compile, console) := Compilation.consoleFlagsFn(scalaVersion.value),
javacOptions ++= Compilation.JavacCompilerFlags,
compileOrder in Compile := CompileOrder.JavaThenScala,
// Dependency settings
resolvers ++= Dependencies.Resolvers,
libraryDependencies ++= Dependencies.AllDependencies
)
def miscSettings(): Seq[Setting[_]] = Seq(
// Wartremover settings
wartremoverErrors in (Compile, compile) := Compilation.WartremoverFlags,
wartremoverErrors in (Test, compile) := Compilation.WartremoverTestFlags,
// General settings
cancelable in Global := true,
// ScalaFmt settings
scalafmtOnCompile := true,
// Scoverage settings
coverageMinimum := 50,
coverageOutputHTML := true,
coverageOutputXML := true,
coverageFailOnMinimum := false,
coverageOutputCobertura := true
)
def assemblySettings(): Seq[Setting[_]] = Seq(
test in assembly := {},
logLevel in assembly := Level.Info,
// The Scala library is provided by Spark execution environment
assemblyOption in assembly := (assemblyOption in assembly).value.copy(includeScala = false),
assemblyMergeStrategy in assembly := {
// Add data source register to assembly jar
case "META-INF/services/org.apache.spark.sql.sources.DataSourceRegister" =>
MergeStrategy.concat
case PathList("META-INF", xs @ _*) => MergeStrategy.discard
case x => MergeStrategy.first
},
assemblyExcludedJars in assembly := {
val cp = (fullClasspath in assembly).value
val exludeSet = Set.empty[String]
cp.filter { jar =>
exludeSet(jar.data.getName)
}
}
)
def apiDocSettings(): Seq[Setting[_]] = Seq(
autoAPIMappings := true,
apiMappings ++= scalaInstance.value.libraryJars.collect {
case file if file.getName.startsWith("scala-library") && file.getName.endsWith(".jar") =>
file -> url(s"http://www.scala-lang.org/api/${scalaVersion.value}/")
}.toMap ++
// Since Java 9+ introduced modules, API links changed, update these
// links based on used Java modules.
Map(
file("/modules/java.sql") -> url(
"https://docs.oracle.com/en/java/javase/11/docs/api/java.sql"
)
),
// Override doc task in 2.11.x versions since linking external Java
// 11+ classes does not work.
(Compile / doc) := Def.taskDyn {
val docTaskValue = (Compile / doc).taskValue
if (scalaBinaryVersion.value == "2.11") {
(Compile / doc / target).toTask
} else {
Def.task(docTaskValue.value)
}
}.value
)
def scalaStyleSettings(): Seq[Setting[_]] = {
// Creates a Scalastyle task that runs with tests
lazy val mainScalastyle = taskKey[Unit]("mainScalastyle")
lazy val testScalastyle = taskKey[Unit]("testScalastyle")
lazy val itTestScalastyle = taskKey[Unit]("itTestScalastyle")
Seq(
scalastyleFailOnError := true,
(scalastyleConfig in Compile) := baseDirectory.value / "project" / "scalastyle-config.xml",
(scalastyleConfig in Test) := baseDirectory.value / "project" / "scalastyle-test-config.xml",
(scalastyleConfig in IntegrationTest) := (scalastyleConfig in Test).value,
(scalastyleSources in IntegrationTest) := Seq((scalaSource in IntegrationTest).value),
mainScalastyle := scalastyle.in(Compile).toTask("").value,
testScalastyle := scalastyle.in(Test).toTask("").value,
itTestScalastyle := scalastyle.in(IntegrationTest).toTask("").value,
(test in Test) := ((test in Test) dependsOn mainScalastyle).value,
(test in Test) := ((test in Test) dependsOn testScalastyle).value,
(test in IntegrationTest) := ((test in IntegrationTest) dependsOn mainScalastyle).value,
(test in IntegrationTest) := ((test in IntegrationTest) dependsOn itTestScalastyle).value
)
}
}