blob: 8bfc5903fafb8937acac857d97ce825f01c98347 [file] [log] [blame]
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 'java'
id 'application'
// since we're using a specific version here, we delay applying the plugin till the all projects
id "com.github.spotbugs" version "3.0.0" apply false
id 'org.hidetake.swagger.generator' version '2.16.0'
id "io.swagger.core.v3.swagger-gradle-plugin" version "2.1.2"
// https://github.com/nebula-plugins/gradle-ospackage-plugin/wiki
id "nebula.ospackage" version "8.3.0"
id 'nebula.ospackage-application' version "8.3.0"
id 'com.google.cloud.tools.jib' version '2.2.0'
}
allprojects {
apply plugin: 'idea'
apply plugin: 'jacoco'
apply plugin: 'checkstyle'
apply plugin: "com.github.spotbugs"
tasks.register("configureKubernetes") {
// figure out the docker registry, make this as easy as possible for new folks
def dockerRegistryString = System.getenv("SIDECAR_DOCKER_REGISTRY")
if(dockerRegistryString != null) {
logger.info("Using ENV SIDECAR_DOCKER_REGISTRY ${dockerRegistryString}")
}
else {
// SIDECAR_DOCKER_REGISTRY not set (likely a local environment), let's try minikube
logger.info("Looking for minikube ip")
new ByteArrayOutputStream().withStream { os ->
try {
def result = exec {
executable = "minikube"
args = ["ip"]
standardOutput = os
}
def output = os.toString()
if(output != "") {
dockerRegistryString = "http://${output.trim()}:5000" // minikube uses port 5000
logger.info("Env variable SIDECAR_DOCKER_REGISTRY not defined, using output of minikube ip ${dockerRegistryString}")
} else {
logger.warn("SIDECAR_DOCKER_REGISTRY not set and minikube ip failed")
}
if(result.exitValue != 0) {
logger.error("Could not find minikube ip: exit code ${result.exitValue}")
}
}
catch (GradleException e) {
// microk8s use this
dockerRegistryString = "http://localhost:5000"
logger.error("Could not auto configure docker registry, please set your SIDECAR_DOCKER_REGISTRY environment variable. Using $dockerRegistryString")
}
}
}
ext.dockerTag = "latest"
ext.dockerGroup = System.getenv("SIDECAR_DOCKER_GROUP") ?: "cassandra_sidecar"
ext.kubernetesNamespace = System.getenv("SIDECAR_KUBERNETES_NAMESPACE") ?: "default"
ext.dockerRegistry = new URI(dockerRegistryString)
ext.dockerRegistryWithoutProtocol = dockerRegistry.getHost() + ":" + dockerRegistry.getPort()
}
repositories {
mavenCentral()
jcenter()
}
checkstyle {
toolVersion '7.8.1'
configFile file("${project.rootDir}/checkstyle.xml")
}
spotbugs {
toolVersion = '4.0.0'
excludeFilter = file("${project.rootDir}/spotbugs-exclude.xml")
}
tasks.withType(com.github.spotbugs.SpotBugsTask) {
reports.xml.enabled = false
reports.html.enabled = true
}
}
group 'org.apache.cassandra'
version project.version
sourceCompatibility = 1.8
// Take the application out once we're running via Cassandra
mainClassName = "org.apache.cassandra.sidecar.CassandraSidecarDaemon"
applicationName = 'cassandra-sidecar'
// Config file location should be in file:/// format for local files,
def confFile = "file:" + File.separator + File.separator + "APP_HOME_TO_REPLACE/conf/sidecar.yaml"
applicationDefaultJvmArgs = ["-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_TO_REPLACE/agents/jolokia-jvm-1.6.0-agent.jar=port=7777,host=localhost"]
startScripts {
doLast {
unixScript.text = unixScript.text.replace("APP_HOME_TO_REPLACE", "\${APP_HOME}")
}
}
run {
confFile = "file:" + File.separator + File.separator + "$projectDir/conf/sidecar.yaml"
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"]
}
sourceSets {
integrationTest {
java {
compileClasspath += main.output + test.output
runtimeClasspath += main.output + test.output
srcDir file('src/integration/java')
}
resources {
srcDirs = [main.resources, "src/integration/resources"]
}
}
}
configurations {
jolokia
integrationTestCompile.extendsFrom testCompile
integrationTestRuntime.extendsFrom testRuntime
}
dependencies {
compile 'io.vertx:vertx-web:3.8.5'
compile 'io.vertx:vertx-dropwizard-metrics:3.8.5'
compile 'io.vertx:vertx-web-client:3.8.5'
compile 'io.swagger.core.v3:swagger-jaxrs2:2.1.0'
compile 'org.jboss.resteasy:resteasy-vertx:3.1.0.Final'
compile group: 'org.jboss.spec.javax.servlet', name: 'jboss-servlet-api_4.0_spec', version: '2.0.0.Final'
// Trying to be exactly compatible with Cassandra's deps
compile 'org.slf4j:slf4j-api:1.7.25'
compile 'ch.qos.logback:logback-core:1.2.3'
compile 'ch.qos.logback:logback-classic:1.2.3'
compile group: 'org.apache.commons', name: 'commons-configuration2', version: '2.7'
compile 'org.webjars:swagger-ui:3.10.0'
runtime group: 'commons-beanutils', name: 'commons-beanutils', version: '1.9.3'
runtime group: 'org.yaml', name: 'snakeyaml', version: '1.26'
jolokia 'org.jolokia:jolokia-jvm:1.6.0:agent'
testCompile "org.junit.jupiter:junit-jupiter-api:${project.junitVersion}"
testCompile "org.junit.jupiter:junit-jupiter-params:${project.junitVersion}"
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:${project.junitVersion}"
testCompile group: 'org.cassandraunit', name: 'cassandra-unit-shaded', version: '3.11.2.0'
testCompile 'com.datastax.cassandra:cassandra-driver-core:3.9.0:tests'
testCompile group: 'org.mockito', name: 'mockito-all', version: '1.10.19'
testCompile group: 'io.vertx', name: 'vertx-junit5', version: '3.8.5'
compile project(":common")
compile project(":cassandra40")
}
task copyCodeStyle(type: Copy) {
from "ide/idea/codeStyleSettings.xml"
into ".idea"
}
// Lets copy the distributions from build/install directory to /bin and /lib
// directories to be aligned with C* distribution format
task copyDist(type: Copy) {
from "$buildDir/install/$applicationName"
into "$projectDir"
}
task copyJolokia(type: Copy) {
from configurations.jolokia
into "$projectDir/src/main/dist/agents"
}
// Lets clean distribution directories along with default build directories.
clean.doLast {
["agents", "bin", "conf", "lib"].each {
println "Deleting directory $projectDir/$it"
delete "$projectDir/$it"
}
println "Deleting generated docs $projectDir/src/main/resources/docs"
delete "$projectDir/src/main/resources/docs"
}
test {
// ordinarily we don't need integration tests
// see the integrationTest task
useJUnitPlatform()
reports {
junitXml.enabled = true
html.enabled = true
}
}
tasks.register("integrationTest", Test) {
jacoco {
enabled = false
}
useJUnitPlatform() {
includeTags "integrationTest"
}
testClassesDirs = sourceSets.integrationTest.output.classesDirs
classpath = sourceSets.integrationTest.runtimeClasspath
shouldRunAfter test
}
// copy the user documentation to the final build
task copyDocs(type: 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 = "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"
description "Sidecar Management Tool for Apache Cassandra"
os = LINUX
user "root"
}
buildRpm {
group = "build"
}
buildDeb {
group = "build"
}
applicationDistribution.from("LICENSE.txt") {
into ""
}
// This task is defined by swagger-gradle-plugin
// Resolves project openAPI specification and saves
// the result in JSON during the build process.
resolve {
outputFileName = 'api'
outputFormat = 'JSON'
prettyPrint = 'TRUE'
classpath = sourceSets.main.runtimeClasspath
resourcePackages = ['org.apache.cassandra.sidecar']
outputDir = file('build/generated/swagger')
}
// copyDist gets called on every build
copyDist.dependsOn installDist, copyJolokia
check.dependsOn checkstyleMain, checkstyleTest, integrationTest, jacocoTestReport
build.dependsOn copyDist, generateReDoc, generateSwaggerUI, copyJolokia, copyDocs
run.dependsOn build