|
1 | 1 | import junitbuild.extensions.dependencyFromLibs |
2 | 2 | import net.ltgt.gradle.errorprone.errorprone |
3 | 3 | import net.ltgt.gradle.nullaway.nullaway |
| 4 | +import java.lang.System.getenv |
4 | 5 |
|
5 | 6 | plugins { |
6 | | - `java-library` |
7 | | - id("net.ltgt.errorprone") |
8 | | - id("net.ltgt.nullaway") |
| 7 | + `java-library` |
| 8 | + id("net.ltgt.errorprone") |
| 9 | + id("net.ltgt.nullaway") |
9 | 10 | } |
10 | 11 |
|
11 | 12 | dependencies { |
12 | | - errorprone(dependencyFromLibs("errorProne-core")) |
13 | | - errorprone(dependencyFromLibs("nullaway")) |
14 | | - constraints { |
15 | | - errorprone("com.google.guava:guava") { |
16 | | - version { |
17 | | - require("33.4.8-jre") |
18 | | - } |
19 | | - because("Older versions use deprecated methods in sun.misc.Unsafe") |
20 | | - } |
21 | | - } |
| 13 | + errorprone(dependencyFromLibs("error-prone-contrib")) |
| 14 | + errorprone(dependencyFromLibs("error-prone-core")) |
| 15 | + errorprone(dependencyFromLibs("nullaway")) |
| 16 | + errorprone(dependencyFromLibs("refaster-runner")) |
22 | 17 | } |
23 | 18 |
|
24 | 19 | nullaway { |
25 | | - onlyNullMarked = true |
| 20 | + onlyNullMarked = true |
26 | 21 | } |
27 | 22 |
|
28 | 23 | tasks.withType<JavaCompile>().configureEach { |
29 | | - options.errorprone { |
30 | | - val shouldDisableErrorProne = java.toolchain.implementation.orNull == JvmImplementation.J9 |
31 | | - if (name == "compileJava" && !shouldDisableErrorProne) { |
32 | | - disable( |
33 | | - |
34 | | - // This check is opinionated wrt. which method names it considers unsuitable for import which includes |
35 | | - // a few of our own methods in `ReflectionUtils` etc. |
36 | | - "BadImport", |
37 | | - |
38 | | - // The findings of this check are subjective because a named constant can be more readable in many cases |
39 | | - "UnnecessaryLambda", |
40 | | - |
41 | | - // Resolving findings for these checks requires ErrorProne's annotations which we don't want to use |
42 | | - "AnnotateFormatMethod", |
43 | | - "DoNotCallSuggester", |
44 | | - "InlineMeSuggester", |
45 | | - "ImmutableEnumChecker", |
46 | | - |
47 | | - // Resolving findings for this check requires using Guava which we don't want to use |
48 | | - "StringSplitter", |
49 | | - |
50 | | - // Produces a lot of findings that we consider to be false positives, for example for package-private |
51 | | - // classes and methods |
52 | | - "MissingSummary", |
53 | | - ) |
54 | | - error("PackageLocation") |
55 | | - } else { |
56 | | - disableAllChecks = true |
57 | | - } |
58 | | - nullaway { |
59 | | - if (shouldDisableErrorProne) { |
60 | | - disable() |
61 | | - } else { |
62 | | - enable() |
63 | | - } |
64 | | - isJSpecifyMode = true |
65 | | - customContractAnnotations.add("org.junit.platform.commons.annotation.Contract") |
66 | | - checkContracts = true |
67 | | - suppressionNameAliases.add("DataFlowIssue") |
68 | | - } |
69 | | - } |
| 24 | + options.errorprone { |
| 25 | + disableWarningsInGeneratedCode = true |
| 26 | + disableAllChecks = !(name == "compileJava" && java.toolchain.implementation.orNull != JvmImplementation.J9) |
| 27 | + if (!disableAllChecks.get()) { |
| 28 | + errorproneArgs.add("-XepOpt:Refaster:NamePattern=^(?!.*Rules\\$).*") // currently failing Refaster; might consider whitelist. |
| 29 | + disable( |
| 30 | + "AnnotateFormatMethod", // We don`t want to use ErrorProne`s annotations. |
| 31 | + "BadImport", // This check is opinionated wrt. which method names it considers unsuitable for import which includes a few of our own methods in `ReflectionUtils` etc. |
| 32 | + "DirectReturn", // https://github.com/junit-team/junit-framework/pull/5006#discussion_r2403984446 |
| 33 | + "DoNotCallSuggester", |
| 34 | + "ImmutableEnumChecker", |
| 35 | + "InlineMeSuggester", |
| 36 | + "MissingSummary", // Produces a lot of findings that we consider to be false positives, for example for package-private classes and methods. |
| 37 | + "StringSplitter", // We don`t want to use Guava. |
| 38 | + "UnnecessaryLambda", // The findings of this check are subjective because a named constant can be more readable in many cases. |
| 39 | + // picnic |
| 40 | + "ConstantNaming", |
| 41 | + "FormatStringConcatenation", |
| 42 | + "IdentityConversion", |
| 43 | + "LexicographicalAnnotationAttributeListing", |
| 44 | + "LexicographicalAnnotationListing", |
| 45 | + "MissingTestCall", |
| 46 | + "NestedOptionals", |
| 47 | + "NonStaticImport", |
| 48 | + "OptionalOrElseGet", |
| 49 | + "PrimitiveComparison", |
| 50 | + "StaticImport", |
| 51 | + "TimeZoneUsage", |
| 52 | + ) |
| 53 | + error( |
| 54 | + "PackageLocation", |
| 55 | + "RedundantStringConversion", |
| 56 | + "RedundantSetterCall", |
| 57 | + "RedundantStringEscape", |
| 58 | + ) |
| 59 | + } |
| 60 | + nullaway { |
| 61 | + if (disableAllChecks.get()) { |
| 62 | + disable() |
| 63 | + } else { |
| 64 | + enable() |
| 65 | + } |
| 66 | + checkContracts = true |
| 67 | + customContractAnnotations.add("org.junit.platform.commons.annotation.Contract") |
| 68 | + isJSpecifyMode = true |
| 69 | + suppressionNameAliases.add("DataFlowIssue") |
| 70 | + } |
| 71 | + } |
70 | 72 | } |
71 | 73 |
|
72 | 74 | tasks.withType<JavaCompile>().named { it.startsWith("compileTest") }.configureEach { |
73 | | - options.errorprone.nullaway { |
74 | | - handleTestAssertionLibraries = true |
75 | | - excludedFieldAnnotations.addAll( |
76 | | - "org.junit.jupiter.api.io.TempDir", |
77 | | - "org.junit.jupiter.params.Parameter", |
78 | | - "org.junit.runners.Parameterized.Parameter", |
79 | | - "org.mockito.Captor", |
80 | | - "org.mockito.InjectMocks", |
81 | | - "org.mockito.Mock", |
82 | | - "org.mockito.Spy", |
83 | | - ) |
84 | | - } |
| 75 | + options.errorprone.nullaway { |
| 76 | + handleTestAssertionLibraries = true |
| 77 | + excludedFieldAnnotations.addAll( |
| 78 | + "org.junit.jupiter.api.io.TempDir", |
| 79 | + "org.junit.jupiter.params.Parameter", |
| 80 | + "org.junit.runners.Parameterized.Parameter", |
| 81 | + "org.mockito.Captor", |
| 82 | + "org.mockito.InjectMocks", |
| 83 | + "org.mockito.Mock", |
| 84 | + "org.mockito.Spy", |
| 85 | + ) |
| 86 | + } |
85 | 87 | } |
0 commit comments