-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild.sbt
109 lines (98 loc) · 4.58 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
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import scala.xml.dtd.DEFAULT
import BuildUtils._
val DEFAULT_SCALA_VERSION = "2.12.20"
val DEFAULT_SPARK_VERSION = "3.5.4"
val DEFAULT_JDK_VERSION = "11"
// version processing logic
val scalaVersion = settingKey[String]("The version of Scala")
val scalaVersionValue = sys.env.getOrElse("SCALA_VERSION", DEFAULT_SCALA_VERSION)
val sparkVersion = settingKey[String]("The version of Spark")
val sparkVersionValue = sys.env.getOrElse("SPARK_VERSION", DEFAULT_SPARK_VERSION)
val jvmFullVersion = settingKey[String]("The JVM version")
val jvmFullVersionValue = sys.props("java.version")
val jvmVersion = settingKey[String]("The JVM major version")
val jvmVersionValue = jvmVersionMap.collectFirst {
case (prefix, (major, _)) if jvmFullVersionValue.startsWith(prefix) => major
}.getOrElse(DEFAULT_JDK_VERSION)
// look up the associated datasketches-java version
val dsJavaVersion = settingKey[String]("The DataSketches Java version")
val dsJavaVersionValue = jvmVersionMap.get(jvmVersionValue).map(_._2).getOrElse("ERROR")
lazy val copyDatasketchesDependencies = taskKey[Seq[File]]("Copy dependencies to a known location")
lazy val cleanPythonVersionFile = taskKey[Unit]("Clean the python version file")
lazy val root = (project in file("."))
.settings(
name := "datasketches-spark",
version := readVersionAndCopyToPython("version.cfg"),
organization := "org.apache.datasketches",
description := "The Apache DataSketches package for Spark",
licenses += ("Apache-2.0", url("http://www.apache.org/licenses/LICENSE-2.0")),
homepage := Some(url("https://datasketches.apache.org/")),
jvmVersion := jvmVersionValue,
dsJavaVersion := dsJavaVersionValue,
sparkVersion := sparkVersionValue,
scalaVersion := scalaVersionValue,
javacOptions ++= Seq("-source", jvmVersion.value, "-target", jvmVersion.value),
scalacOptions ++= Seq("-encoding", "UTF-8", "-release", jvmVersion.value),
Test / javacOptions ++= Seq("-source", jvmVersion.value, "-target", jvmVersion.value),
Test / scalacOptions ++= Seq(
"-encoding", "UTF-8",
"-release", jvmVersion.value,
"-deprecation",
"-feature",
"-unchecked",
"-Xlint"
),
libraryDependencies ++= Seq(
"org.apache.datasketches" % "datasketches-java" % dsJavaVersion.value,
"org.scala-lang" % "scala-library" % scalaVersion.value % "provided", // scala3-library may need to use %%
("org.apache.spark" %% "spark-sql" % sparkVersion.value % "provided").cross(CrossVersion.for3Use2_13),
"org.scalatest" %% "scalatest" % "3.2.19" % "test",
"org.scalatestplus" %% "junit-4-13" % "3.2.19.0" % "test"
),
copyDatasketchesDependencies := {
// we want to copy non-provided/non-test dependencies to a known location
// so that they can be obtained easily
val targetLibDir = target.value / "lib"
val listFile = targetLibDir / "dependencies.txt"
val dependencies = (Compile / dependencyClasspath).value
BuildUtils.copyDependenciesAndWriteList(targetLibDir, dependencies, listFile)
},
Compile / packageBin := (Compile / packageBin)
.dependsOn(copyDatasketchesDependencies)
.andFinally(readVersionAndCopyToPython("version.cfg")).value,
Test / testOptions += Tests.Argument(TestFrameworks.ScalaTest, "-oD"),
// additional options for java 17
Test / fork := {
if (jvmVersion.value == "17") true
else (Test / fork).value
},
Test / javaOptions ++= {
if (jvmVersion.value == "17") {
Seq("--add-modules=jdk.incubator.foreign",
"--add-exports=java.base/sun.nio.ch=ALL-UNNAMED"
)
} else {
Seq.empty
}
},
Test / logBuffered := false,
Test / logLevel := Level.Info,
cleanPythonVersionFile := BuildUtils.cleanPythonVersionFile(),
clean := clean.dependsOn(cleanPythonVersionFile).value
)