-
Notifications
You must be signed in to change notification settings - Fork 13
/
build.gradle
258 lines (215 loc) · 9.16 KB
/
build.gradle
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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
import org.nosphere.apache.rat.RatTask
/*
* 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 java.nio.file.Files
import java.nio.file.Paths
plugins {
id 'java'
id 'java-library'
id 'com.github.johnrengelman.shadow' version '8.1.1'
// Release Audit Tool (RAT) plugin for checking project licenses
id("org.nosphere.apache.rat") version "0.8.1"
}
repositories {
mavenCentral()
}
ext.scalaLabel = System.getenv("SCALA_VERSION") ?: "${scala}"
println("Scala version: ${ext.scalaLabel}")
ext.sparkLabel = (System.getenv("SPARK_VERSION") ?: "${spark}").split(/\./)[0]
println("Spark version: ${ext.sparkLabel}")
ext.jdkLabel = System.getenv("JDK_VERSION") ?: "${analyticsJDKLevel}"
println("Java source/target compatibility level: ${ext.jdkLabel}")
// validate the builder is indeed using the correct JDK_VERSION as specified
String actualJdkVersion = System.getProperty("java.version")
if (!actualJdkVersion.startsWith(ext.jdkLabel))
{
def errorMessage = "Invalid jdk version (Found: ${actualJdkVersion}) for jdk-${ext.jdkLabel} build"
throw new RuntimeException(errorMessage)
}
ext.dependencyLocation = (System.getenv("CASSANDRA_DEP_DIR") ?: "${rootDir}/dependencies") + "/"
def buildDir = layout.buildDirectory.get().asFile.toPath()
def ratExcludeFilePath = buildDir.resolve(".rat-excludes.txt")
System.out.println("Rat exclude file:" + ratExcludeFilePath)
def profile = "profiles/scala-${ext.scalaLabel}-spark-${ext.sparkLabel}-jdk-${ext.jdkLabel}.gradle"
if (!file(profile).exists()) {
throw new InvalidUserDataException("Profile ${profile} does not exist, which indicates this combination of Scala, Spark, and Java is unsupported.\n" +
"Please either add an appropriate profile if this combination should work, or use a different one.")
}
println("Using profile ${profile}")
apply(from: profile)
apply(plugin: 'idea')
// Force checkstyle and rat to run before test tasks for faster feedback
def codeCheckTasks = task("codeCheckTasks")
tasks.register('copyCodeStyle', Copy) {
from('ide/idea/codeStyleSettings.xml')
into('.idea')
}
tasks.idea.dependsOn(tasks.copyCodeStyle)
tasks.register('copyInspections', Copy) {
from('ide/idea/Project_Default.xml')
into('.idea/inspectionProfiles')
}
tasks.idea.dependsOn(tasks.copyInspections)
tasks.register('buildIgnoreRatList', Exec) {
description 'Builds a list of ignored files for the rat task from the unversioned git files'
commandLine 'bash', '-c', 'git clean --force -d --dry-run -x | grep -v "Would skip" | cut -c 14- '
doFirst {
// make sure the build directory exists so rat task can run independently
Files.createDirectories(buildDir)
standardOutput new FileOutputStream(ratExcludeFilePath.toFile())
}
// allows task to fail when git/cut commands are unavailable or fail
ignoreExitValue = true
}
rat {
doFirst {
def excludeFilePath = ratExcludeFilePath
def excludeLines = Files.readAllLines(excludeFilePath)
excludeLines.each { line ->
if (line.endsWith("/")) {
excludes.add("**/" + line + "**")
} else {
excludes.add(line)
}
}
}
// List of Gradle exclude directives, defaults to ['**/.gradle/**']
excludes.add("**/build/**")
excludes.add("CHANGES.txt")
excludes.add("**/org.apache.spark.sql.sources.DataSourceRegister")
// Sidecar for build process
excludes.add("**/cassandra-sidecar/**")
// Documentation files
excludes.add("**/docs/src/**")
// gradle files
excludes.add("gradle/**")
excludes.add("gradlew")
excludes.add("gradlew.bat")
// resource files for test
excludes.add("**/test**/resources/**")
// resources
excludes.add("**/resources/sidecar.version")
excludes.add("**/dependencies/**")
// Rat excludes file, one directive per line
excludeFile.set(ratExcludeFilePath.toFile())
// XML, TXT and HTML reports directory, defaults to 'build/reports/rat'
reportDir.set(file("build/reports/rat"))
}
tasks.named('rat').configure {
dependsOn(buildIgnoreRatList)
}
subprojects {
apply(plugin: 'java-library')
apply(plugin: 'checkstyle')
sourceCompatibility = "${project.rootProject.ext.jdkLabel}"
targetCompatibility = "${project.rootProject.ext.jdkLabel}"
configurations {
configureEach {
resolutionStrategy {
// Force set the jackson version that matches with the one from spark's dependencies.
// Do not favor newer jackson version from others, because that jackson module scala has a strict check
// on the paired jackson dependency.
force("com.fasterxml.jackson.module:jackson-module-scala_${scalaMajorVersion}:${jacksonScalaModuleVersion}")
force("com.fasterxml.jackson.core:jackson-core:${jacksonVersion}")
force("com.fasterxml.jackson.core:jackson-annotations:${jacksonVersion}")
force("com.fasterxml.jackson.core:jackson-databind:${jacksonVersion}")
}
}
}
tasks.withType(JavaCompile) {
if ("${project.rootProject.ext.jdkLabel}" == '1.8') {
// Unfortunately, we can't use release here. We can only use public APIs when using release.
// org.apache.cassandra.spark.bulkwriter.util.FastByteOperations uses sun.misc.Unsafe which is causing the build
// to fail.
options.compilerArgs += ['-source', '8', '-target', '8']
} else {
options.release = 11
}
}
archivesBaseName = "${project.name}"
if ("${project.rootProject.ext.sparkLabel}" == '3') {
archivesBaseName = "${archivesBaseName}_spark3"
}
archivesBaseName = "${archivesBaseName}_${scalaMajorVersion}"
repositories {
mavenCentral()
mavenLocal {
url Paths.get(dependencyLocation)
content {
includeModule("org.apache.cassandra", "cassandra-sidecar")
includeGroup("org.apache.cassandra.sidecar")
}
}
}
dependencies {
compileOnly(group: 'com.intellij', name: 'annotations', version: "${project.rootProject.intellijVersion}")
testCompileOnly(group: 'com.intellij', name: 'annotations', version: "${project.rootProject.intellijVersion}")
}
sourceSets {
main {
java {
srcDirs += ["src/main/spark${project.rootProject.ext.sparkLabel}",
"src/main/scala-${scalaMajorVersion}-spark-${sparkMajorVersion}"]
}
}
test {
java {
srcDirs += ["src/test/spark${project.rootProject.ext.sparkLabel}",
"src/test/scala-${scalaMajorVersion}-spark-${sparkMajorVersion}"]
}
}
}
test {
def heapDumpPath = "${project.rootProject.rootDir}/build/${project.name}/heapDumps"
Files.createDirectories(Paths.get(heapDumpPath))
if (JavaVersion.current().isJava11Compatible()) {
def JDK11_OPTIONS = ['-Djdk.attach.allowAttachSelf=true',
'--add-exports', 'java.base/jdk.internal.misc=ALL-UNNAMED',
'--add-exports', 'java.base/jdk.internal.ref=ALL-UNNAMED',
'--add-exports', 'java.base/sun.nio.ch=ALL-UNNAMED',
'--add-exports', 'java.management.rmi/com.sun.jmx.remote.internal.rmi=ALL-UNNAMED',
'--add-exports', 'java.rmi/sun.rmi.registry=ALL-UNNAMED',
'--add-exports', 'java.rmi/sun.rmi.server=ALL-UNNAMED',
'--add-exports', 'java.sql/java.sql=ALL-UNNAMED',
'--add-opens', 'java.base/java.lang.module=ALL-UNNAMED',
'--add-opens', 'java.base/jdk.internal.loader=ALL-UNNAMED',
'--add-opens', 'java.base/jdk.internal.ref=ALL-UNNAMED',
'--add-opens', 'java.base/jdk.internal.reflect=ALL-UNNAMED',
'--add-opens', 'java.base/jdk.internal.math=ALL-UNNAMED',
'--add-opens', 'java.base/jdk.internal.module=ALL-UNNAMED',
'--add-opens', 'java.base/jdk.internal.util.jar=ALL-UNNAMED',
'--add-opens', 'jdk.management/com.sun.management.internal=ALL-UNNAMED',
'-XX:+HeapDumpOnOutOfMemoryError',
"-XX:HeapDumpPath=${heapDumpPath}"]
jvmArgs(JDK11_OPTIONS)
println("JVM arguments for $project.name are $allJvmArgs")
}
}
codeCheckTasks.dependsOn(tasks.withType(Checkstyle))
codeCheckTasks.dependsOn(tasks.withType(RatTask))
tasks.withType(Test) {
shouldRunAfter(codeCheckTasks)
shouldRunAfter(tasks.withType(Checkstyle))
shouldRunAfter(tasks.withType(RatTask))
}
tasks.register('printCodeVersion') {
println()
println(version)
}
}