-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbuild.gradle
More file actions
executable file
·419 lines (346 loc) · 12.7 KB
/
build.gradle
File metadata and controls
executable file
·419 lines (346 loc) · 12.7 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
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
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
//----------------------------------------------------------------
//
// Gradle project core configuration
//
//----------------------------------------------------------------
// Setup gradle and its plugins
plugins {
// Setup gradle for java library builds
id 'java-library'
// // The one fat jar with dependencies (without shade)
// id "com.github.onslip.gradle-one-jar" version "1.0.5"
// Shadow plugin used to build the shade jar
id 'com.github.johnrengelman.shadow' version '2.0.4'
// jacoco code coverage for test
id 'jacoco'
}
// Dependency providers to fetch from
repositories {
google()
gradlePluginPortal()
mavenCentral()
// You can declare any other Maven/Ivy/file repository here.
}
//----------------------------------------------------------------
//
// Project versioning
//
//----------------------------------------------------------------
// The Project version
version = '4.1.0'
project.ext {
batikVer = '1.7'
}
// Setup java compilation version
sourceCompatibility = 1.8
targetCompatibility = 1.8
//----------------------------------------------------------------
//
// JavaCommons-core integration
//
//----------------------------------------------------------------
// JavaCommons core compilation
task buildJavaCommonsCore(type: GradleBuild) {
buildFile = './JavaCommons-core/build.gradle'
tasks = ['fatJar']
}
// Dependency linkage of core project build
compileJava.dependsOn buildJavaCommonsCore
//----------------------------------------------------------------
//
// Project dependencies
//
//----------------------------------------------------------------
// Dependencies used in the build
dependencies {
// JavaCommons dependencies
//---------------------------------------
// Get and compile against the -all.jar lib file from javacommons core
// note that compileOnly + testImplementation ensures this file is not included
// in any of the 3 jar builds, but still make it part of the test suite
implementation fileTree(dir: './JavaCommons-core/build/libs', include: ['*-all.jar'])
testImplementation fileTree(dir: './JavaCommons-core/build/libs', include: ['*-all.jar'])
// This dependencies is exported to consumers, that is to say found on their compile classpath.
//-------------------------------------------------------------------------------------------------------------------
// iText
api files("./lib/iText.jar")
//batik SVG
// https://mvnrepository.com/artifact/org.w3c.dom/svg
implementation 'org.kie.modules:org-apache-batik:6.1.0.Beta1'
// https://mvnrepository.com/artifact/batik/batik-util
compile group: 'org.apache.xmlgraphics', name: 'batik-util', version: project.batikVer
// https://mvnrepository.com/artifact/batik/batik-dom
compile group: 'org.apache.xmlgraphics', name: 'batik-dom', version: project.batikVer
// https://mvnrepository.com/artifact/org.apache.xmlgraphics/batik-svg-dom
compile group: 'org.apache.xmlgraphics', name: 'batik-svg-dom', version: project.batikVer
// https://mvnrepository.com/artifact/org.apache.xmlgraphics/batik-svggen
compile group: 'org.apache.xmlgraphics', name: 'batik-svggen', version: project.batikVer
// https://mvnrepository.com/artifact/org.apache.xmlgraphics/batik-svgpp
compile group: 'org.apache.xmlgraphics', name: 'batik-svgpp', version: project.batikVer
// https://mvnrepository.com/artifact/org.apache.xmlgraphics/batik-bridge
compile group: 'org.apache.xmlgraphics', name: 'batik-bridge', version: project.batikVer
// https://mvnrepository.com/artifact/org.apache.xmlgraphics/batik-transcoder
compile group: 'org.apache.xmlgraphics', name: 'batik-transcoder', version: project.batikVer
// https://mvnrepository.com/artifact/org.apache.xmlgraphics/batik-gvt
compile group: 'org.apache.xmlgraphics', name: 'batik-gvt', version: project.batikVer
// https://mvnrepository.com/artifact/org.apache.xmlgraphics/batik-codec
compile group: 'org.apache.xmlgraphics', name: 'batik-codec', version: project.batikVer
// // Connection pooling
// api "com.zaxxer:HikariCP:3.1.0" // connection pooling
// // OJDBC driver connection
// api files("./lib/jsql/ojdbc6.jar") // for oracle
// api "org.xerial:sqlite-jdbc:3.25.2" // for sqlite
// api "mysql:mysql-connector-java:6.0.6" // for mysql
// // Newer MSSQL connection (THIS DOES NOT WORK)
// // api "com.microsoft.sqlserver:mssql-jdbc:7.2.1.jre8" // for mssql
// // Older MSSQL connection (THIS DOES)
// api "net.sourceforge.jtds:jtds:1.3.1" // for mssql
// // Hazelcast
// api "com.hazelcast:hazelcast:3.11.4"
// api "com.hazelcast:hazelcast-client:3.11.4"
// // PostgresSQL library
// api "org.postgresql:postgresql:42.2.5"
// This dependencies is used internally, and not exposed to consumers on their own compile classpath.
//-------------------------------------------------------------------------------------------------------------------
// implementation 'com.google.guava:guava:23.0'
// Testing dependencies
//-------------------------------------------------------------------------------------------------------------------
testImplementation 'junit:junit:4.12'
testImplementation 'com.carrotsearch:junit-benchmarks:0.7.2'
}
//----------------------------------------------------------------
//
// Jar build steps
//
//----------------------------------------------------------------
//
// Base JAR build settings
//
// `gradle jar`
//
jar {
// Archive name overwrite
archiveName = project.name+"-"+project.version+"-nodep"+".jar"
description = "Build the "+archiveName+" with no dependencies"
// Inherit the main jar manifest
manifest {
attributes(
'Implementation-Title': project.name,
'Implementation-Version': project.version
)
}
}
//
// Shadow jar - dependencies are shaded
//
// `gradle shadowJar`
//
shadowJar {
// Archive name overwrite
archiveName = project.name+"-"+project.version+"-shade"+".jar"
description = "Build the "+archiveName+" with all dependencies shaded"
// Inherit the main jar manifest
manifest {
inheritFrom project.tasks.jar.manifest
}
// Shade depencies under "picoded.shade"
relocate "picoded", "picoded"
relocate "org", "picoded.shade.org"
relocate "com", "picoded.shade.com"
relocate "oracle", "picoded.shade.oracle"
}
//
// Fat jar - dependencies are included, and not shaded
//
// `gradle shadowJar`
//
task fatJar(type: com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar) {
// Archive name overwrite
archiveName = project.name+"-"+project.version+"-all"+".jar"
description = "Build the "+archiveName+" with all dependencies"
//
// Note that the following is extended heavily from the default setup of shadowJar task
// See : https://github.com/johnrengelman/shadow/blob/7ef6fc2699627f172b05a3bd3523201d63bb588f/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/ShadowJavaPlugin.groovy#L38-L63
//
// NOTE : I dunno what this is - but it was setup in the default config
conventionMapping.with {
map('classifier') {
'all'
}
}
// Build from the main output
from sourceSets.main.output
// Load default configurations
configurations = [project.configurations.findByName('runtimeClasspath') ? project.configurations.runtimeClasspath : project.configurations.runtime]
// Inherit the main jar manifest
manifest {
inheritFrom project.tasks.jar.manifest
}
// Project dependencies libraries
doFirst {
def files = project.configurations.findByName(com.github.jengelman.gradle.plugins.shadow.ShadowBasePlugin.CONFIGURATION_NAME).files
if (files) {
def libs = [project.tasks.jar.manifest.attributes.get('Class-Path')]
libs.addAll files.collect { "${it.name}" }
manifest.attributes 'Class-Path': libs.findAll { it }.join(' ')
}
}
// Exclude signed jar signatures?
exclude('META-INF/INDEX.LIST', 'META-INF/*.SF', 'META-INF/*.DSA', 'META-INF/*.RSA')
// Disable relocation
relocate "picoded", "picoded"
relocate "org", "org"
relocate "com", "com"
relocate "oracle", "oracle"
}
// Define the equivalent of buildAll
// for the build process done by "gradle build"
artifacts {
archives fatJar
archives shadowJar
archives jar
}
//----------------------------------------------------------------
//
// Concurent test threads
//
//----------------------------------------------------------------
test {
// Exclude performance related test
exclude "**/perf/*.java"
exclude "**/*_perf*"
// Setup test to run on parllel threads = to number of processors by default
if (project.hasProperty('maxParallelForks')) {
maxParallelForks = project.maxParallelForks as int
} else {
// As our test tends to be io-blocked rather then cpu
// we will run more tests in parallels
maxParallelForks = (Runtime.runtime.availableProcessors() * 2) as int
}
// Set up the number of tests per fork
if (project.hasProperty('forkEvery')) {
forkEvery = project.forkEvery as int
}
}
// Custom incremental test running
// (Only run tests directly related to a changed class)
class TestWatcher extends Test {
@TaskAction
void executeTests(IncrementalTaskInputs inputs) {
// Process list of changed .classes file
if (inputs.incremental) {
// Include pattern to indicate which test classes should run
this.filter.includePatterns = []
// Get the test folder directories
// def outputDir = this.project.sourceSets['test'].output.classesDir.absolutePath;
// Iterate list of input files
inputs.outOfDate { InputFileDetails change ->
// Get the candidate file
def candidate = change.file.absolutePath
// Consider only if it ends with .class file
if (candidate.endsWith('.class')) {
// Get the filename (after processing)
def pathSplit = candidate.replace('.class', '').split("/")
// Strip off the folder path
def filename = pathSplit[ pathSplit.size() - 1 ]
// Add the filename into the include pattern
this.filter.includePatterns += "*"+filename+"*"
// candidate = candidate
// .replace('.class', '')
// .replace(outputDir, '')
// .substring(1)
// .replace(File.separator, '.')
// this.filter.includePatterns += candidate
}
}
}
// Execute the respective test
super.executeTests()
}
}
// Incremental testing
task incrementalTest(type: TestWatcher) {
// Exclude performance related test
exclude "**/perf/*.java"
exclude "**/*_perf*"
// Setup test to run on parllel threads = to number of processors by default
if (project.hasProperty('maxParallelForks')) {
maxParallelForks = project.maxParallelForks as int
} else {
// As our test tends to be io-blocked rather then cpu
// we will run more tests in parallels
maxParallelForks = (Runtime.runtime.availableProcessors() * 2) as int
}
// Set up the number of tests per fork
if (project.hasProperty('forkEvery')) {
forkEvery = project.forkEvery as int
}
}
//----------------------------------------------------------------
//
// Custom src-beautify / prettifier
// and compile aliases (with auto srcBeautify)
//
//----------------------------------------------------------------
// srcBeautify, with input file mapping (to skip srcBeautify steps if needed)
def srcBeautify_inputFiles = project.fileTree(dir: "src", include: "**/*.java")
def srcBeautify_outputDir = "${project.buildDir}/build-util/java-fromatter/output/"
task srcBeautify(type:Exec) {
// Input file tracking support,
// this helps gradle skip this command if no files was changed
inputs.files(srcBeautify_inputFiles)
outputs.dir(srcBeautify_outputDir)
workingDir '.'
// The build formatter command
if (System.getProperty('os.name').toLowerCase(Locale.ROOT).contains('windows')) {
// Does nothing as of now, as windows support is not yet in place
} else {
commandLine './build-util/java-formatter/parallel_format.sh','./src'
}
}
task prettify(dependsOn: srcBeautify)
// Doing compile alias for java
task src(dependsOn: compileJava)
task source(dependsOn: src)
task compile(dependsOn: src)
// Forcing srcBeautify on src step
src.dependsOn srcBeautify
//----------------------------------------------------------------
//
// Jacoco test coverage
//
//----------------------------------------------------------------
jacoco {
toolVersion = "0.8.0"
}
jacocoTestReport {
// Build the report
reports {
xml.enabled true
csv.enabled true
// Report format compatible with codeconv.io
xml.destination file("${buildDir}/reports/jacoco/report.xml")
csv.destination file("${buildDir}/reports/jacoco/report.csv")
}
}
//----------------------------------------------------------------
//
// Quick multibuild steps
//
//----------------------------------------------------------------
task buildAll {
description = "Build all 3 jars: jar, shadowJar, fatJar"
dependsOn jar
dependsOn shadowJar
dependsOn fatJar
}
task gogo {
description = "src and test"
dependsOn src
dependsOn test
}
task testAndBuildAll {
description = "Performs the full test suite, then build all 3 jars: jar, shadowJar, fatJar"
dependsOn jacocoTestReport
dependsOn buildAll
}