blob: c3d14cf5b657c4362073191e8e6487480f486ff0 [file] [log] [blame]
// 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.
// This file contains common tasks and configuration for checking the quality of the code.
apply plugin: "checkstyle" // Ensures Java code follows the defined coding style.
apply plugin: "com.github.spotbugs" // Performs static code analysis to look for bugs in Java code.
apply plugin: "pmd" // Performs static code analysis to look for common code smells in Java code.
apply plugin: "com.github.ben-manes.versions" // Provides a task to determine which dependencies have updates.
apply plugin: "ru.vyarus.animalsniffer" // Ensures Java code uses APIs from a particular version of Java.
apply plugin: "scalafmt"
checkstyle {
configFile = file("$rootDir/kudu_style.xml")
configProperties = [
"checkstyle.suppressions.file" : "$rootDir/checkstyle_suppressions.xml"
]
ignoreFailures = true
showViolations = true
}
// Create an aggregate checkstyle task.
// This simplifies running checkstyle on all the code by only needing one task instead of multiple in your command.
task checkstyle(dependsOn: [checkstyleMain, checkstyleTest], group: "Verification") {
description = "Run Checkstyle analysis."
}
spotbugs {
toolVersion = versions.spotBugs
ignoreFailures = true
effort = "max"
}
tasks.withType(com.github.spotbugs.SpotBugsTask) {
reports {
xml.enabled false
html.enabled true
}
}
// Create an aggregate spotbugs task.
// This simplifies running spotbugs on all the code by only needing one task instead of multiple in your command.
task spotbugs(dependsOn: [spotbugsMain, spotbugsTest], group: "Verification") {
description = "Run SpotBugs analysis."
}
pmd {
toolVersion = versions.pmd
ignoreFailures = true
}
scalafmt {
configFilePath = "$rootDir/.scalafmt.conf"
}
// Run scalafmt on compile
tasks.withType(ScalaCompile) {
if (!propertyExists("skipFormat")) {
dependsOn("scalafmtAll")
}
}
// Create an aggregate pmd task.
// This simplifies running pmd on all the code by only needing one task instead of multiple in your command.
task pmd(dependsOn: [pmdMain, pmdTest], group: "Verification") {
description = "Run PMD analysis."
}
// Disable error-prone if we are compiling with Java 10+ util support is added.
// See https://github.com/google/error-prone/issues/860
if (!JavaVersion.current().isJava10Compatible()) {
// Enable error-prone.
// Running with '-Derrorprone-fix=...' can instruct error-prone to automatically fix issues.
apply plugin: "net.ltgt.errorprone"
// Performs static code analysis to look for bugs in Java code.
tasks.withType(JavaCompile) {
options.compilerArgs += ['-XepExcludedPaths:.*/build/generated.*/.*',
'-XepAllErrorsAsWarnings']
def fix = propertyWithDefault("errorprone-fix", "")
if (!fix.isEmpty()) {
options.compilerArgs += ['-XepPatchChecks:' + fix, '-XepPatchLocation:IN_PLACE']
}
}
// Set a specific version of Error Prone
dependencies {
errorprone libs.errorProne
}
}
// Define a Java API signature for use by animal-sniffer. It'll enforce that all
// Java API usage adheres to this signature.
dependencies {
signature "org.codehaus.mojo.signature:java1$javaCompatibility:1.0@signature"
}
// Create an aggregate animal-sniffer task.
// This simplifies running animal-sniffer on all the code by only needing one task instead of multiple in your command.
task animalsniffer(dependsOn: [animalsnifferMain, animalsnifferTest], group: "Verification") {
description = "Run animal-sniffer analysis."
}
// Configure the versions plugin to only show dependency updates for released versions.
dependencyUpdates {
revision = "release"
resolutionStrategy = {
componentSelection { rules ->
rules.all { ComponentSelection selection ->
boolean rejected = ["snap", "alpha", "beta", "rc", "cr", "m"].any { qualifier ->
selection.candidate.version ==~ /(?i).*[.-]${qualifier}[.\d-].*/
}
if (rejected) {
selection.reject("Release candidate")
}
}
}
}
}