forked from ben-manes/caffeine
/
codeQuality.gradle
203 lines (180 loc) · 5.41 KB
/
codeQuality.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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
/**
* Configurations for code quality analysis
*/
import static org.gradle.util.GradleVersion.version
apply plugin: 'org.kordamp.gradle.stats'
apply plugin: 'org.checkerframework'
apply plugin: 'com.github.spotbugs'
apply plugin: 'net.ltgt.errorprone'
apply plugin: 'net.ltgt.nullaway'
apply plugin: 'org.sonarqube'
apply plugin: 'java-library'
apply plugin: 'checkstyle'
apply plugin: 'jacoco'
apply plugin: 'pmd'
configurations {
checkstyleConfig
}
repositories {
flatDir {
dirs "${rootDir}/build/libs"
}
}
dependencies {
checkerFramework libraries.checkerFramework
checkstyleConfig gradlePlugins.checkstyle
errorproneJavac libraries.errorproneJavac
errorprone libraries.errorproneCore
errorprone libraries.nullaway
errorprone name: 'caffeine_local'
}
// Gradle rewrites the compiler's dependency on Caffeine to a project dependency, which fails
// Instead we have to download and trick the build to put the jar on the compiler's classpath
// See the downloadCaffeineLocal() task and https://github.com/gradle/gradle/issues/11625
task downloadCaffeineLocal() {
def url = 'https://repo1.maven.org/maven2/com/github/ben-manes/caffeine/caffeine/2.9.0/caffeine-2.9.0.jar'
def local = file("${rootDir}/build/libs/caffeine_local.jar")
if (!local.exists()) {
local.parentFile.mkdirs()
new URL(url).withInputStream{ input -> local.withOutputStream{ it << input }}
}
}
javadoc.options.links(
'https://checkerframework.org/api/',
'https://lightbend.github.io/config/latest/api/',
"https://guava.dev/releases/${versions.guava}/api/docs/",
"https://docs.oracle.com/en/java/javase/${JavaVersion.current().majorVersion}/docs/api/")
jar {
manifest.attributes 'Bundle-License': 'https://www.apache.org/licenses/LICENSE-2.0'
metaInf {
from "${rootDir}/LICENSE"
}
}
checkerFramework {
checkers = [
'org.checkerframework.checker.nullness.NullnessChecker',
]
extraJavacArgs = [ '-Werror' ]
excludeTests = true
}
checkstyle {
showViolations = true
toolVersion = pluginVersions.checkstyle
config = resources.text.fromArchiveEntry(configurations.checkstyleConfig, 'google_checks.xml')
}
spotbugs {
effort = 'max'
excludeFilter = file("${rootDir}/config/spotbugs/exclude.xml")
toolVersion = [version(pluginVersions.spotbugs), version(toolVersion.get())].max().version
}
pmd {
ruleSets = []
ruleSetConfig = resources.text.fromFile(file("${rootDir}/config/pmd/rulesSets.xml"))
toolVersion = [version(pluginVersions.pmd), version(toolVersion)].max().version
}
jacoco {
toolVersion = [version(pluginVersions.jacoco), version(toolVersion)].max().version
}
jacocoTestReport {
group = 'Coverage reports'
description = 'Generates a test coverage report for a project'
reports {
xml.enabled = true
html.enabled = true
}
}
sonarqube {
properties {
property 'sonar.organization', 'caffeine'
property 'sonar.projectKey', 'caffeine:caffeine'
property 'sonar.login', System.env.'SONAR_TOKEN'
property 'sonar.host.url', 'https://sonarcloud.io'
}
}
tasks.withType(JavaExec) {
jvmArgs += [
'--add-exports', 'jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED',
'--add-exports', 'jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED',
'--add-exports', 'jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED',
'--add-exports', 'jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED',
'--add-exports', 'jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED',
]
}
tasks.withType(JavaCompile).configureEach {
dependsOn downloadCaffeineLocal
options.compilerArgs << '-Xlint:all,-auxiliaryclass'
options.encoding = 'UTF-8'
options.errorprone {
option('ClassName')
option('ComparisonContractViolated')
option('DepAnn')
option('DivZero')
option('EqualsBrokenForNull')
option('FunctionalInterfaceClash')
option('LockMethodChecker')
option('LongLiteralLowerCaseSuffix')
option('MissingDefault')
option('MixedArrayDimensions')
option('NoAllocation')
option('NumericEquality')
option('RedundantThrows')
option('RemoveUnusedImports')
option('TimeUnitMismatch')
option('UnlockMethod')
option('UnnecessaryDefaultInEnumSwitch')
disable('EmptyCatch')
disable('MissingSummary')
error('NullAway')
excludedPaths = "${buildDir}/generated-sources/.*"
nullaway {
annotatedPackages.add('com.github.benmanes.caffeine')
}
}
checkerFramework.skipCheckerFramework = true
}
tasks.named('compileTestJava').configure {
options.errorprone.disable('NullAway')
}
tasks.withType(Test) {
if (System.properties.containsKey('debug')) {
jvmArgs '-Xdebug', '-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005'
}
options {
jvmArgs '-XX:SoftRefLRUPolicyMSPerMB=0'
}
if (System.env.'CI') {
reports.html.enabled = false
}
testLogging {
events 'skipped', 'failed'
exceptionFormat 'full'
showCauses = true
showExceptions = true
showStackTraces = true
}
}
tasks.withType(Checkstyle) {
enabled = System.properties.containsKey('checkstyle')
group = 'Checkstyle'
reports {
xml.enabled = false
html.enabled = true
}
}
afterEvaluate {
tasks.findAll { it.name.startsWith('spotbugs') }.each {
it.enabled = System.properties.containsKey('spotbugs')
it.group = 'SpotBugs'
it.reports {
html.enabled = true
}
}
}
tasks.withType(Pmd) {
enabled = System.properties.containsKey('pmd')
group = 'PMD'
reports {
xml.enabled = false
html.enabled = true
}
}