This repository has been archived by the owner on Apr 2, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
quality-java.gradle
166 lines (143 loc) · 4.96 KB
/
quality-java.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
apply plugin: 'checkstyle'
apply plugin: 'pmd'
apply plugin: 'findbugs'
// FIXME(https://docs.gradle.org/4.1-rc-2/userguide/plugins.html#sec:build_scripts_only):
// Replace buildscript+apply with just
// plugins {
// id 'net.ltgt.errorprone' version '0.0.10'
// }
buildscript {
repositories {
maven { url 'https://plugins.gradle.org/m2/' }
}
dependencies {
classpath 'net.ltgt.gradle:gradle-errorprone-plugin:0.0.11'
classpath 'gradle.plugin.org.jlleitschuh.gradle:ktlint-gradle:2.1.1'
}
}
apply plugin: net.ltgt.gradle.errorprone.ErrorPronePlugin
apply plugin: org.jlleitschuh.gradle.ktlint.KtlintPlugin
ext {
configPath = buildscript.sourceFile.getParent()
}
checkstyle {
// https://docs.gradle.org/current/dsl/org.gradle.api.plugins.quality.CheckstyleExtension.html
// http://checkstyle.sourceforge.net/releasenotes.html
toolVersion '8.4'
}
pmd {
// https://docs.gradle.org/current/dsl/org.gradle.api.plugins.quality.PmdExtension.html
toolVersion '5.8.1'
}
findbugs {
// https://docs.gradle.org/current/dsl/org.gradle.api.plugins.quality.FindBugsExtension.html
toolVersion '3.0.1'
}
def definePrintTask(target, sourceSetPrefix) {
def name = target.getName().capitalize()
def sourceSetName = target.getName().substring(sourceSetPrefix.length())
def type = target.getClass().getSimpleName().toLowerCase().replace("_decorated", "")
task "print$name", {
doLast {
def destination = target.reports.getXml().getDestination()
.getAbsolutePath()
ant.xslt(
in: destination,
out: destination + '.txt',
style: "$configPath/$type/text.xslt",
)
System.err.println file(destination + '.txt').text
}
}
target.finalizedBy "print$name"
def checkQualityTaskName = "checkQuality$sourceSetName"
if (!tasks.findByName(checkQualityTaskName)) {
task "$checkQualityTaskName"
}
tasks[checkQualityTaskName].dependsOn(target)
def ktlintTaskName = "ktlint${sourceSetName}Check"
if (tasks.findByName(ktlintTaskName)) {
tasks[checkQualityTaskName].dependsOn(ktlintTaskName)
}
}
project.afterEvaluate {
tasks.withType(FindBugs) {
// https://docs.gradle.org/current/dsl/org.gradle.api.plugins.quality.FindBugs.html
effort = 'max'
// Contrary to what one may think, 'low' means 'tell about everything'
reportLevel = 'low'
excludeFilter = file("$configPath/findbugs/filter.xml")
reports {
emacs.enabled false
html.enabled false
text.enabled false
xml {
enabled true
setWithMessages true
}
}
definePrintTask(it, 'findbugs')
}
tasks.withType(Checkstyle) {
ignoreFailures = false
configFile = file("$configPath/checkstyle/checkstyle.xml")
showViolations = false
reports {
xml.enabled true
html.enabled false
}
definePrintTask(it, 'checkstyle')
}
tasks.withType(Pmd) {
ignoreFailures = false
ruleSetFiles = files("$configPath/pmd/ruleset.xml")
consoleOutput = false
reports {
xml.enabled true
html.enabled false
}
definePrintTask(it, 'pmd')
}
}
tasks.withType(JavaCompile) {
options.compilerArgs += [
// Disable "No processor claimed any of these annotations" (@Inject).
// Disable "MethodParameters introduced in 52 an ignored in 51" (migration).
'-Xlint:all,-processing,-classfile',
'-XepAllDisabledChecksAsWarnings',
'-XepDisableWarningsInGeneratedCode',
// Don't want to annotate all modifiable references with "@Var".
'-Xep:Var:OFF',
// Sad but need Firebase-generated R.java to have @Generated.
'-Xep:ConstantField:OFF',
'-Xep:PrivateConstructorForUtilityClass:OFF',
// Doesn't play well with Dagger.
'-Xep:InjectScopeAnnotationOnInterfaceOrAbstractClass:OFF',
// Doesn't work with ButterKnife.
'-Xep:ConstructorLeaksThis:OFF',
// FIXME(https://github.com/google/error-prone/issues/708): NPE
'-Xep:FieldMissingNullable:OFF',
// We don't have a package providing @Immutable annotation.
'-Xep:ImmutableEnumChecker:OFF',
// This works well on Android now with Desugar.
'-Xep:StaticOrDefaultInterfaceMethod:OFF',
'-Werror',
]
}
dependencies {
findbugsPlugins 'jp.skypencil.findbugs.slf4j:bug-pattern:1.2.4@jar'
}
task resolveDependencies {
doLast {
project.configurations.each { configuration ->
if (configuration.isCanBeResolved()) {
configuration.resolve()
}
}
project.buildscript.configurations.each { configuration ->
if (configuration.isCanBeResolved()) {
configuration.resolve()
}
}
}
}