1/* 2 * Copyright 2017 The Android Open Source Project 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 17package androidx.build 18 19import net.ltgt.gradle.errorprone.ErrorProneToolChain 20import org.gradle.api.tasks.compile.JavaCompile 21 22const val ERROR_PRONE_VERSION = "com.google.errorprone:error_prone_core:2.2.0" 23 24fun JavaCompile.configureWithErrorProne(toolChain: ErrorProneToolChain) { 25 this.toolChain = toolChain 26 27 val compilerArgs = this.options.compilerArgs 28 compilerArgs += listOf( 29 "-XDcompilePolicy=simple", // Workaround for b/36098770 30 "-XepExcludedPaths:.*/(build/generated|external)/.*", 31 32 // Enforce the following checks. 33 "-Xep:RestrictTo:OFF", 34 "-Xep:ParameterNotNullable:ERROR", 35 "-Xep:MissingOverride:ERROR", 36 "-Xep:JdkObsolete:ERROR", 37 "-Xep:EqualsHashCode:ERROR", 38 "-Xep:NarrowingCompoundAssignment:ERROR", 39 "-Xep:ClassNewInstance:ERROR", 40 "-Xep:ClassCanBeStatic:ERROR", 41 "-Xep:SynchronizeOnNonFinalField:ERROR", 42 "-Xep:OperatorPrecedence:ERROR", 43 "-Xep:IntLongMath:ERROR", 44 "-Xep:MissingFail:ERROR", 45 "-Xep:JavaLangClash:ERROR", 46 "-Xep:PrivateConstructorForUtilityClass:ERROR", 47 "-Xep:TypeParameterUnusedInFormals:ERROR", 48 "-Xep:StringSplitter:ERROR", 49 "-Xep:ReferenceEquality:ERROR", 50 51 // Nullaway 52 "-XepIgnoreUnknownCheckNames", // https://github.com/uber/NullAway/issues/25 53 "-Xep:NullAway:ERROR", 54 "-XepOpt:NullAway:AnnotatedPackages=android.arch,android.support,androidx" 55 ) 56} 57