-
Notifications
You must be signed in to change notification settings - Fork 948
Expand file tree
/
Copy pathbuild.gradle
More file actions
245 lines (204 loc) · 6.49 KB
/
build.gradle
File metadata and controls
245 lines (204 loc) · 6.49 KB
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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
buildscript {
repositories {
jcenter()
}
dependencies {
// https://github.com/melix/japicmp-gradle-plugin/issues/36
classpath 'com.google.guava:guava:31.1-jre'
}
}
plugins {
id 'java'
id 'jacoco'
id 'checkstyle'
id 'me.champeau.gradle.japicmp' version '0.4.6'
id 'maven-publish'
}
sourceSets {
jmh {
}
}
configurations {
jmhImplementation {
extendsFrom implementation
}
}
checkstyle {
toolVersion '10.0'
}
//We are disabling lint checks for tests
tasks.named("checkstyleTest").configure({
enabled = false
})
tasks.named("checkstyleJmh").configure({
enabled = false
})
apply from: rootProject.file('gradle/versioning.gradle')
version = getVersionFromFile()
group = GROUP
logger.lifecycle("Using version ${version} for ${name} group $group")
import me.champeau.gradle.japicmp.JapicmpTask
project.afterEvaluate {
def versions = project.ext.testInJavaVersions
for (pluginJavaTestVersion in versions) {
def taskName = "testInJava-${pluginJavaTestVersion}"
tasks.register(taskName, Test) {
def versionToUse = taskName.split("-").getAt(1) as Integer
description = "Runs unit tests on Java version ${versionToUse}."
project.logger.quiet("Test will be running in ${versionToUse}")
group = 'verification'
javaLauncher.set(javaToolchains.launcherFor {
languageVersion = JavaLanguageVersion.of(versionToUse)
})
shouldRunAfter(tasks.named('test'))
}
tasks.named('check') {
dependsOn(taskName)
}
}
project.configure(project) {
def baselineVersion = project.ext.baselineCompareVersion
task('apiDiff', type: JapicmpTask, dependsOn: 'jar') {
oldClasspath.from(files(getBaselineJar(project, baselineVersion)))
newClasspath.from(files(jar.archiveFile))
onlyModified = true
failOnModification = true
ignoreMissingClasses = true
htmlOutputFile = file("$buildDir/reports/apiDiff/apiDiff.html")
txtOutputFile = file("$buildDir/reports/apiDiff/apiDiff.txt")
doLast {
project.logger.quiet("Comparing against baseline version ${baselineVersion}")
}
}
}
}
private static File getBaselineJar(Project project, String baselineVersion) {
// Use detached configuration: https://github.com/square/okhttp/blob/master/build.gradle#L270
def group = project.group
try {
def baseline = "${project.group}:${project.name}:$baselineVersion"
project.group = 'virtual_group_for_japicmp'
def dependency = project.dependencies.create(baseline + "@jar")
return project.configurations.detachedConfiguration(dependency).files.find {
it.name == "${project.name}-${baselineVersion}.jar"
}
} finally {
project.group = group
}
}
ext {
baselineCompareVersion = '4.1.0'
testInJavaVersions = [8, 11, 17, 21]
}
java {
toolchain {
languageVersion = JavaLanguageVersion.of(11)
}
}
compileJava {
exclude 'module-info.java'
// Required to be compatible with JDK 8+
options.release = 8
}
javadoc {
// Exclude internal implementation package from javadoc
excludes = ['com/auth0/jwt/impl', 'module-info.java']
}
dependencies {
implementation 'com.fasterxml.jackson.core:jackson-core:2.21.2'
implementation 'com.fasterxml.jackson.core:jackson-databind:2.21.2'
testImplementation 'org.bouncycastle:bcprov-jdk15on:1.70'
testImplementation 'junit:junit:4.13.2'
testImplementation 'net.jodah:concurrentunit:0.4.6'
testImplementation 'org.hamcrest:hamcrest:2.2'
testImplementation 'org.mockito:mockito-core:4.11.0'
jmhImplementation sourceSets.main.output
jmhImplementation 'org.openjdk.jmh:jmh-core:1.37'
jmhAnnotationProcessor 'org.openjdk.jmh:jmh-generator-annprocess:1.37'
}
jacoco {
toolVersion = "0.8.10"
}
jacocoTestReport {
reports {
xml.enabled = true
html.enabled = true
}
}
test {
testLogging {
events "skipped", "failed", "standardError"
exceptionFormat "short"
}
}
task compileModuleInfoJava(type: JavaCompile) {
classpath = files()
source = 'src/main/java/module-info.java'
destinationDir = compileJava.destinationDir
doLast {
def descriptor = new File(compileJava.destinationDir, 'module-info.class')
def dest = new File(compileJava.destinationDir, 'META-INF/versions/9')
ant.move file: descriptor, todir: dest
}
doFirst {
options.compilerArgs = [
'--release', '9',
'--module-path', compileJava.classpath.asPath
]
}
}
compileTestJava {
options.release = 8
options.compilerArgs = ["-Xlint:deprecation"]
}
def testJava8 = tasks.register('testJava8', Test) {
description = 'Runs unit tests on Java 8.'
group = 'verification'
javaLauncher.set(javaToolchains.launcherFor {
languageVersion = JavaLanguageVersion.of(8)
})
shouldRunAfter(tasks.named('test'))
}
def testJava17 = tasks.register('testJava17', Test) {
description = 'Runs unit tests on Java 17.'
group = 'verification'
javaLauncher.set(javaToolchains.launcherFor {
languageVersion = JavaLanguageVersion.of(17)
})
shouldRunAfter(tasks.named('test'))
}
def testJava21 = tasks.register('testJava21', Test) {
description = 'Runs unit tests on Java 21.'
group = 'verification'
javaLauncher.set(javaToolchains.launcherFor {
languageVersion = JavaLanguageVersion.of(21)
})
shouldRunAfter(tasks.named('test'))
}
tasks.named('check') {
dependsOn(testJava8)
dependsOn(testJava17)
dependsOn(testJava21)
}
jar {
manifest.attributes('Multi-Release': 'true')
}
compileModuleInfoJava.dependsOn compileJava
classes.dependsOn compileModuleInfoJava
// you can pass any arguments JMH accepts via Gradle args.
// Example: ./gradlew runJMH --args="-lrf"
tasks.register('runJMH', JavaExec) {
description 'Run JMH benchmarks.'
group 'verification'
main 'org.openjdk.jmh.Main'
classpath sourceSets.jmh.runtimeClasspath
args project.hasProperty("args") ? project.property("args").split() : ""
}
tasks.register('jmhHelp', JavaExec) {
description 'Prints the available command line options for JMH.'
group 'help'
main 'org.openjdk.jmh.Main'
classpath sourceSets.jmh.runtimeClasspath
args '-h'
}
apply from: rootProject.file('gradle/maven-publish.gradle')