blob: f7c8d241766fe9b51bc2e95cb4f340dfb0a4508d [file] [log] [blame]
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}")
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")
}
}
// uncomment the line below for local development
//mavenLocal()
}
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)
}
}