-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
302 lines (244 loc) · 8.12 KB
/
build.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
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
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
/*
* This file is part of Jeso.
* Copyright (c) 2019-2022 Jonathan Bradley Whited
*
* SPDX-License-Identifier: LGPL-3.0-or-later
*/
plugins {
id 'java-library'
id 'com.github.spotbugs' version '4.7.+'
id 'com.diffplug.spotless' version '5.14.+'
id 'maven-publish'
}
repositories {
mavenCentral()
//maven { url 'https://jitpack.io' }
//google()
}
group = 'com.esotericpig.jeso' // Must be set for publishing!
version = '0.3.7'
project.ext {
author = 'Jonathan Bradley Whited'
license = 'LGPL-3.0-or-later'
homepage = 'https://github.com/esotericpig/jeso'
summary = 'Java utils'
description = 'Java utils to make Java less verbose.'
javaVersion = 8
charset = 'UTF-8'
encoding = 'UTF-8'
locale = 'en_US'
compilerArgs = [] //['-Xlint:deprecation','-Xlint:unchecked']
javadoc.title = "${project.name.capitalize()} v${version}"
}
tasks.withType(JavaCompile) {
options.encoding = project.encoding
options.release = project.javaVersion
options.compilerArgs += project.compilerArgs
}
dependencies {
// Dependencies exported to consumers, found on their compile classpath.
//api 'org.apache.commons:commons-math3:3.6.+'
//api fileTree(dir: 'libs',include: ['**/*.jar'])
// Dependencies used internally, not exposed to consumers' own compile classpath.
//implementation 'com.google.guava:guava:30.0-jre'
// JUnit Jupiter API for testing.
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.+'
// JUnit Jupiter Engine for testing.
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine'
}
import com.github.spotbugs.snom.SpotBugsTask
import java.util.regex.Pattern
tasks.named('test') {
// Use JUnit platform for unit tests.
useJUnitPlatform()
testLogging {
events 'passed','skipped','failed'
}
}
spotbugs {
excludeFilter = file('spotbugs_exclude.xml')
}
tasks.withType(SpotBugsTask) {
reports {
xml.enabled = false
html {
enabled = true
stylesheet = 'fancy-hist.xsl'
}
}
}
spotless {
encoding project.encoding
java {
// FIXME: Doesn't work with Java v16+ for now.
//removeUnusedImports()
//importOrder()
indentWithSpaces()
trimTrailingWhitespace()
endWithNewline()
}
}
/*========
* Tasks *
========*/
defaultTasks 'clean','buildRelease','buildFatRelease'
task(buildFatRelease,type: Jar,dependsOn: ['classes','test','check','javadoc']) {
group 'Build'
description 'Assembles everything necessary for a release into one "fat" jar.'
// Include dependencies (jars) to final jar; a "fat jar".
from configurations.runtimeClasspath.collect {
it.isDirectory() ? it : zipTree(it)
}
classifier 'all'
from javadoc.destinationDir
from sourceSets.main.allSource
from sourceSets.main.output
}
// Do not use "GradleBuild" because then you cannot do "-x check".
task(buildRelease,dependsOn: ['build','test','check','jar','javadoc','javadocZip','sourcesJar']) {
group 'Build'
description 'Assembles everything necessary for a release: Jar, Javadoc Zip, Sources Jar, etc.'
}
task(checkGradleW) {
group 'Checksum'
description 'Check the SHA-256 sum of the Gradle Wrapper Jar.'
doLast {
ant.checksum(file: "$rootDir/gradle/wrapper/gradle-wrapper.jar"
,algorithm: 'SHA-256',property: 'gradlewJarSum')
String gradlewJarSum = ant.properties['gradlewJarSum']
String gradlewSumSum = new File(
"$rootDir/gradle/wrapper/gradle-wrapper.jar.sha256")
.getText('UTF-8').split('\\s+')[0]
println()
println('[[ Gradle Wrapper Jar Checksum ]]')
println()
println("/gradle/wrapper/gradle-wrapper.jar $gradlewJarSum")
println("/gradle/wrapper/gradle-wrapper.jar.sha256 $gradlewSumSum")
println("Do they match? "
+ (gradlewJarSum.equals(gradlewSumSum) ? 'OK' : 'NOT a match!'))
}
}
task(wgetGradleWSums) {
group 'Checksum'
description 'Download the SHA-256 sums for the Gradle Wrapper Jars.'
doLast {
String checksums = new URL('https://gradle.org/release-checksums').getText('UTF-8')
String gradleVersion = "v${project.gradle.gradleVersion}"
int index = checksums.indexOf(gradleVersion + '<')
int gradlebIndex = checksums.indexOf('Binary-only',index)
int gradlecIndex = checksums.indexOf('Complete',index)
int gradlewIndex = checksums.indexOf('Wrapper',index)
// Split on "<code>" or "</code>".
Pattern pattern = Pattern.compile(
'\\s*<\\s*/?\\s*code\\s*>\\s*',Pattern.CASE_INSENSITIVE)
String gradlebSum = pattern.split(checksums.substring(gradlebIndex,gradlebIndex + 200))[1]
String gradlecSum = pattern.split(checksums.substring(gradlecIndex,gradlecIndex + 200))[1]
String gradlewSum = pattern.split(checksums.substring(gradlewIndex,gradlewIndex + 200))[1]
println()
println("[[ Gradle Checksums for ${gradleVersion} ]]")
println()
println("Put this in /gradle/wrapper/gradle-wrapper.properties:")
println("distributionSha256Sum=${gradlebSum}")
println()
println("Save this to /gradle/wrapper/gradle-wrapper.jar.sha256:")
println("${gradlewSum} gradle-wrapper.jar")
println()
println('Complete (-all) Zip:')
println("${gradlecSum}")
}
}
tasks.withType(Jar) {
manifest {
attributes(
// Add dependencies to classpath.
'Class-Path': configurations.runtimeClasspath.collect {
it.getName()
}.join(' '),
'Specification-Title': project.name,
'Specification-Version': project.version,
'Specification-Author': project.author,
'Specification-Vendor': project.author,
'Specification-License': project.license,
'Implementation-Title': project.group,
'Implementation-Version': project.version,
'Implementation-Author': project.author,
'Implementation-Vendor': project.author,
'Implementation-License': project.license,
'Lib-Homepage': project.homepage,
'Lib-Summary': project.summary,
'Lib-Description': project.ext.description,
)
}
from("${rootDir}/") {
include 'LICENSE','README.md'
}
}
javadoc {
options {
author = true
charSet = project.charset
encoding = project.encoding
locale = project.locale
memberLevel = JavadocMemberLevel.PROTECTED // Show public & protected (don't show private).
version = true
// FIXME: Remove this after v1.0.0.
addStringOption('Xdoclint:none','-quiet')
}
}
task(javadocZip,type: Zip,dependsOn: javadoc) {
group 'Documentation'
description 'Assembles a Zip archive containing the Javadoc.'
classifier 'javadoc'
from javadoc.destinationDir
}
task(sourcesJar,type: Jar,dependsOn: classes) {
group 'Documentation'
description 'Assembles a Jar archive containing the main source code (*.java).'
classifier 'sources'
from sourceSets.main.allSource
}
/*=============
* Publishing *
=============*/
// Execute "./gradlew rsyncToGhp" for a dry run.
// Execute "./gradlew rsyncToGhp -Pdeploy=true" for actually deploying.
task(rsyncToGhp,type: Exec) {
group 'Deploy'
description "Rsync docs to my GitHub Page's repo; not useful for others"
boolean isDryRun = !project.hasProperty('deploy') || !deploy
executable 'rsync'
args += '-ahv'
//args += '--delete-after'
args += '--progress'
if(isDryRun) {
args += '--dry-run'
}
args += 'build/docs/javadoc/'
args += "../esotericpig.github.io/docs/${project.name}/javadoc"
doLast {
if(isDryRun) {
println()
println('Execute "./gradlew rsyncToGhp -Pdeploy=true" for actually deploying (non-dry-run)')
}
}
}
publishing {
repositories {
maven {
name = 'GitHubPackages'
url = uri("https://maven.pkg.github.com/esotericpig/${project.name}")
// In ~/.gradle/gradle.properties:
// gpr.user=username # Your GitHub username
// gpr.key=token # Your GitHub token (or password)
credentials {
username = project.findProperty('gpr.user') ?: System.getenv("USERNAME")
password = project.findProperty('gpr.key') ?: System.getenv("PASSWORD")
}
}
}
publications {
gpr(MavenPublication) {
from(components.java)
}
}
}