1/* 2 * Copyright (C) 2017. Uber Technologies 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17import net.ltgt.gradle.errorprone.CheckSeverity 18buildscript { 19 repositories { 20 mavenCentral() 21 google() // For Gradle 4.0+ 22 } 23 24 dependencies { 25 classpath 'com.android.tools.build:gradle:7.3.0' 26 classpath 'com.vanniktech:gradle-maven-publish-plugin:0.25.3' 27 } 28} 29plugins { 30 id "com.diffplug.spotless" version "6.23.3" 31 id "net.ltgt.errorprone" version "3.1.0" apply false 32 id "com.github.johnrengelman.shadow" version "8.1.1" apply false 33 id "me.champeau.jmh" version "0.7.1" apply false 34 id "com.github.ben-manes.versions" version "0.50.0" 35 id "com.felipefzdz.gradle.shellcheck" version "1.4.6" 36} 37 38repositories { 39 // to get the google-java-format jar and dependencies 40 mavenCentral() 41} 42 43apply from: "gradle/dependencies.gradle" 44 45subprojects { project -> 46 project.apply plugin: "net.ltgt.errorprone" 47 project.dependencies { 48 errorprone deps.build.errorProneCore 49 } 50 project.tasks.withType(JavaCompile) { 51 dependsOn(installGitHooks) 52 options.compilerArgs += [ 53 "-Xlint:deprecation", 54 "-Xlint:rawtypes", 55 "-Xlint:unchecked", 56 "-Werror" 57 ] 58 options.errorprone { 59 // disable warnings in generated code; AutoValue code fails UnnecessaryParentheses check 60 disableWarningsInGeneratedCode = true 61 // this check is too noisy 62 check("StringSplitter", CheckSeverity.OFF) 63 // https://github.com/google/error-prone/issues/3366 64 check("CanIgnoreReturnValueSuggester", CheckSeverity.OFF) 65 // turn up various checks 66 check("WildcardImport", CheckSeverity.ERROR) 67 check("MissingBraces", CheckSeverity.ERROR) 68 check("TypeToString", CheckSeverity.ERROR) 69 check("SymbolToString", CheckSeverity.ERROR) 70 check("MultipleTopLevelClasses", CheckSeverity.ERROR) 71 check("ClassName", CheckSeverity.ERROR) 72 check("PackageLocation", CheckSeverity.ERROR) 73 check("UnnecessaryAnonymousClass", CheckSeverity.ERROR) 74 check("UnusedException", CheckSeverity.ERROR) 75 // To enable auto-patching, uncomment the line below, replace [CheckerName] with 76 // the checker(s) you want to apply patches for (comma-separated), and above, disable 77 // "-Werror" 78 // errorproneArgs.addAll("-XepPatchChecks:[CheckerName]", "-XepPatchLocation:IN_PLACE") 79 } 80 } 81 82 // Target JDK 8. We need to use the older sourceCompatibility / targetCompatibility settings to get 83 // the build to work on JDK 11+. Once we stop supporting JDK 8, switch to using the javac "release" option 84 tasks.withType(JavaCompile) { 85 java.sourceCompatibility = "1.8" 86 java.targetCompatibility = "1.8" 87 } 88 89 tasks.withType(Test).configureEach { 90 maxParallelForks = Runtime.runtime.availableProcessors().intdiv(2) ?: 1 91 } 92 93 repositories { 94 mavenCentral() 95 google() 96 } 97 98 // For some reason, spotless complains when applied to the jar-infer folder itself, even 99 // though there is no top-level :jar-infer project 100 if (project.name != "jar-infer") { 101 project.apply plugin: "com.diffplug.spotless" 102 spotless { 103 java { 104 googleJavaFormat() 105 } 106 } 107 } 108} 109 110spotless { 111 predeclareDeps() 112 groovyGradle { 113 target '**/*.gradle' 114 greclipse() 115 indentWithSpaces(4) 116 trimTrailingWhitespace() 117 endWithNewline() 118 } 119} 120spotlessPredeclare { 121 java { googleJavaFormat('1.18.1') } 122 groovyGradle { 123 greclipse() 124 } 125} 126 127shellcheck { 128 useDocker = false 129 shellcheckBinary = "shellcheck" 130 sourceFiles = 131 fileTree(".") { 132 include("**/*.sh") 133 } 134} 135 136//////////////////////////////////////////////////////////////////////// 137// 138// Google Java Format pre-commit hook installation 139// 140 141tasks.register('installGitHooks', Copy) { 142 from(file('config/hooks/pre-commit-stub')) { 143 rename 'pre-commit-stub', 'pre-commit' 144 } 145 into file('.git/hooks') 146 fileMode 0777 147} 148