-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathbuild.gradle
427 lines (372 loc) · 14.4 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
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
/*
* 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 com.github.spotbugs.snom.SpotBugsTask
import org.nosphere.apache.rat.RatTask
import java.nio.file.Files
import java.nio.file.Paths
buildscript {
dependencies {
// findBugs needs a newer version of Guava in the buildscript.
// otherwise it throws an exception
classpath "com.google.guava:guava:28.2-jre"
}
}
plugins {
id 'idea'
id 'java'
id 'application'
// Used to sign built artifacts
id 'signing'
// since we're using a specific version here, we delay applying the plugin till the all projects
id "com.github.spotbugs" version "6.0.20" apply false
// Help resolve dependency conflicts between jib and ospackage
// See: https://github.com/GoogleContainerTools/jib/issues/4235#issuecomment-2088829367
id('com.google.cloud.tools.jib') version '3.4.4' apply false
// https://github.com/nebula-plugins/gradle-ospackage-plugin/wiki
id "com.netflix.nebula.ospackage" version "11.10.0"
id 'com.netflix.nebula.ospackage-application' version "11.10.0"
id 'org.asciidoctor.jvm.convert' version '3.3.2'
// Release Audit Tool (RAT) plugin for checking project licenses
id("org.nosphere.apache.rat") version "0.8.0"
id 'jacoco'
}
ext {
// A common method to handle loading gradle properties with a default when
// no definition is found. The property value is determined by the following
// priority order (top is highest priority):
// - gradle property (-Pproperty=value)
// - system property (-Dproperty=value)
// - environment variable
// - default value
// See more details on gradle property handling here:
// https://docs.gradle.org/current/userguide/build_environment.html#sec:gradle_properties_and_system_properties
propertyWithDefault = { property, defaultValue ->
def value = defaultValue
def envValue = System.getenv("CASSANDRA_DEP_DIR")
if (envValue != null) {
value = envValue
}
def systemValue = System.getProperty(property)
if (systemValue != null) {
value = systemValue
}
def projectValue = project.hasProperty(property) ? project.property(property) : null
if (projectValue != null) {
value = projectValue
}
return value
}
// Returns true if the property has been set, otherwise false.
propertyExists = { property ->
System.getenv(property) != null || System.getProperty(property) != null || project.hasProperty(property)
}
dependencyLocation = propertyWithDefault("CASSANDRA_DEP_DIR", "${rootDir}/dtest-jars") + "/"
// This allows simplified builds and local maven installs.
forceSigning = propertyExists("forceSigning")
skipSigning = propertyExists("skipSigning")
shouldSign =
// Always sign artifacts if -PforceSigning is passed.
forceSigning ||
// Skip signing artifacts by default if -PskipSigning is passed.
(!skipSigning
// Sign artifacts if the version is not a snapshot, and we are uploading them to maven.
&& !version.endsWith("SNAPSHOT")
&& project.gradle.startParameter.taskNames.any { it.contains("upload") })
}
// Force checkstyle, rat, and spotBugs to run before test tasks for faster feedback
def codeCheckTasks = task("codeCheckTasks")
allprojects {
apply plugin: 'jacoco'
apply plugin: 'checkstyle'
// do not run spot-bug on test-specific sub-projects
if (!it.name.startsWith('integration-') && !it.name.startsWith("test-")) {
apply plugin: "com.github.spotbugs"
spotbugs {
toolVersion = '4.2.3'
excludeFilter = file("${project.rootDir}/spotbugs-exclude.xml")
}
codeCheckTasks.dependsOn(tasks.withType(SpotBugsTask))
tasks.withType(Test) {
// define the order of the tasks, if SpotBugsTask runs
shouldRunAfter(tasks.withType(SpotBugsTask))
}
}
repositories {
mavenCentral()
// for dtest jar
mavenLocal()
}
checkstyle {
toolVersion '7.8.1'
configFile file("${project.rootDir}/checkstyle.xml")
}
// must run the dependant tasks in order to run codeCheckTasks
codeCheckTasks.dependsOn(tasks.withType(Javadoc))
codeCheckTasks.dependsOn(tasks.withType(Checkstyle))
codeCheckTasks.dependsOn(tasks.withType(RatTask))
tasks.withType(Test) {
// define the order of the tasks, if the below tasks runs
shouldRunAfter(codeCheckTasks)
shouldRunAfter(tasks.withType(Checkstyle))
shouldRunAfter(tasks.withType(RatTask))
}
}
group 'org.apache.cassandra'
version project.version
application {
// Take the application out once we're running via Cassandra
mainClassName = "org.apache.cassandra.sidecar.CassandraSidecarDaemon"
applicationName = 'cassandra-sidecar'
applicationDefaultJvmArgs = ["PLACEHOLDER"]
}
startScripts {
doLast {
// Config file location should be in file:/// format for local files,
def confFile = "file:" + File.separator + File.separator + "\${APP_HOME}/conf/sidecar.yaml"
// As of Gradle version 7.2, the generated bin/cassandra-sidecar file by default is configured to not allow
// shell fragments. Thus, variables like APP_HOME are treated as literals, which prevents us from being able to
// start up cassandra-sidecar. See this comment on bin/cassandra-sidecar (line 208):
//
// # Collect all arguments for the java command:
// # * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
// # and any embedded shellness will be escaped.
// # * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
// # treated as '${Hostname}' itself on the command line.
//
// Replacing the placeholder after the script has been generated will preserve the semantics from Gradle < 7.2.
// See this Gradle issue for more context: https://github.com/gradle/gradle/issues/18170.
def defaultJvmOpts = ["-Dsidecar.logdir=./logs",
"-Dsidecar.config=" + confFile,
"-Dlogback.configurationFile=./conf/logback.xml",
"-Dvertx.logger-delegate-factory-class-name=io.vertx.core.logging.SLF4JLogDelegateFactory",
"-javaagent:\${APP_HOME}/agents/jolokia-jvm-1.6.0-agent.jar=port=7777,host=localhost"]
unixScript.text = unixScript.text.replace("DEFAULT_JVM_OPTS='\"PLACEHOLDER\"'",
"DEFAULT_JVM_OPTS=\"${defaultJvmOpts.join(" ")}\"")
windowsScript.delete()
}
}
run {
def confFile = System.getProperty("sidecar.config", "file:" + File.separator + File.separator + "$projectDir/conf/sidecar.yaml")
println "Sidecar configuration file $confFile"
jvmArgs = ["-Dsidecar.logdir=./logs",
"-Dsidecar.config=" + confFile,
"-Dlogback.configurationFile=./conf/logback.xml",
"-Dvertx.logger-delegate-factory-class-name=io.vertx.core.logging.SLF4JLogDelegateFactory",
"-javaagent:$projectDir/agents/jolokia-jvm-1.6.0-agent.jar=port=7777,host=localhost"]
}
distributions {
main {
distributionBaseName = 'apache-cassandra-sidecar'
contents {
from 'LICENSE.txt'
// Include the "agents" directory in the distribution
from('agents') {
into('agents')
}
// Include the "conf" directory in the distribution
from('conf') {
into('conf')
}
setDuplicatesStrategy(DuplicatesStrategy.INCLUDE)
}
}
// Packages the sources as a tarball for distribution
sources {
distributionBaseName = 'apache-cassandra-sidecar'
distributionClassifier = 'src'
contents {
from '.'
include '**/*.*'
exclude '**.gradle/**'
exclude '**.idea/**'
exclude 'agents/**'
exclude 'bin/**'
exclude 'dtest-jars/**'
exclude '**lib/**'
exclude '**logs/**'
exclude '**/build/**'
exclude '**/out/**'
exclude '**/target/**'
}
}
}
configurations {
jolokia
runtime.exclude(group: "com.google.code.findbugs", module: "jsr305")
runtime.exclude(group: "org.codehaus.mojo", module: "animal-sniffer-annotations")
runtime.exclude(group: "com.google.guava", module: "listenablefuture")
runtime.exclude(group: "org.checkerframework", module: "checker-qual")
runtime.exclude(group: "com.google.errorprone", module: "error_prone_annotations")
runtime.exclude(group: 'com.github.jnr', module: 'jnr-ffi')
runtime.exclude(group: 'com.github.jnr', module: 'jnr-posix')
}
if (JavaVersion.current().isJava11Compatible()) {
dependencies {
runtimeOnly(project(':server'))
jolokia 'org.jolokia:jolokia-jvm:1.6.0:agent'
}
}
jar {
doFirst {
// Store current Cassandra Sidecar build version in an embedded resource file;
// the file is either created or overwritten, and ignored by Git source control
Files.createDirectories(Paths.get("$projectDir/server-common/src/main/resources"))
new File("$projectDir/server-common/src/main/resources/sidecar.version").text = version
println("Created sidecar.version")
}
}
tasks.register('copyIdeaSettings', Copy) {
from "ide/idea"
into ".idea"
}
tasks.named('idea').configure {
dependsOn copyIdeaSettings
}
tasks.register('copyJolokia') {
doLast {
copy {
into "$projectDir"
into("agents") {
from configurations.jolokia
}
}
}
}
// Lets clean distribution directories along with default build directories.
clean.doLast {
["agents"].each {
println "Deleting directory $projectDir/$it"
delete "$projectDir/$it"
}
println "Deleting generated docs $projectDir/server/src/main/resources/docs"
delete "$projectDir/server/src/main/resources/docs"
}
subprojects {
jacocoTestReport {
reports {
xml.setRequired(true)
html.setRequired(true)
csv.setRequired(false)
}
}
test {
finalizedBy jacocoTestReport // report is always generated after tests run
}
}
// copy the user documentation to the final build
tasks.register('copyDocs', Copy) {
dependsOn ':docs:asciidoctor'
from(tasks.getByPath(":docs:asciidoctor").outputs) {
include "**/*.html"
}
into "build/docs/"
exclude "tmp"
}
/**
* General configuration for linux packages.
* Can be overridden in the buildRpm and buildDeb configuration
* We can put dependencies here, such as java, but unfortunately since java is distributed
* in an inconsistent manner depending on the version you want (8 vs 11) we can't include Java
* as a requirement without the install breaking if you want to use a different version
*/
ospackage {
packageName = "apache-cassandra-sidecar"
version = project.version
// ospackage puts packages into /opt/[package] by default
// which is _technically_ the right spot for packages
link("/usr/local/bin/cassandra-sidecar", "/opt/cassandra-sidecar/bin/cassandra-sidecar")
license = "Apache License 2.0"
summary = "Sidecar Management Tool for Apache Cassandra"
description = "Sidecar Management Tool for Apache Cassandra"
os = LINUX
user = "root"
}
buildRpm {
group = "distribution"
}
buildDeb {
group = "distribution"
}
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 | cut -c 14-"
doFirst {
mkdir(buildDir)
standardOutput new FileOutputStream("${buildDir}/.rat-excludes.txt")
}
// allows task to fail when git/cut commands are unavailable or fail
ignoreExitValue = true
}
rat {
doFirst {
def excludeFilePath = Paths.get("${buildDir}/.rat-excludes.txt")
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")
// 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/**")
// XML, TXT and HTML reports directory, defaults to 'build/reports/rat'
reportDir.set(file("build/reports/rat"))
}
distZip.dependsOn copyJolokia
distTar.dependsOn copyJolokia
installDist.dependsOn copyJolokia
check.dependsOn codeCheckTasks
if (JavaVersion.current().isJava11Compatible()) {
build.dependsOn codeCheckTasks, copyJolokia, copyDocs
}
run.dependsOn build
tasks.named('rat').configure {
dependsOn(buildIgnoreRatList)
}
tasks.named('distTar').configure {
compression = Compression.GZIP
archiveExtension = "tar.gz"
}
tasks.named('sourcesDistTar').configure {
compression = Compression.GZIP
archiveExtension = "tar.gz"
}
signing {
required { shouldSign }
if (shouldSign) {
// Use gpg-agent to sign
useGpgCmd()
}
sign distZip
sign distTar
sign sourcesDistTar
sign buildDeb
sign buildRpm
}