-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathbuild.gradle
More file actions
executable file
·290 lines (241 loc) · 8.19 KB
/
build.gradle
File metadata and controls
executable file
·290 lines (241 loc) · 8.19 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
//----------------------------------------------------------------
//
// 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'
// Setup java compilation version
sourceCompatibility = 1.8
targetCompatibility = 1.8
//----------------------------------------------------------------
//
// Project dependencies
//
//----------------------------------------------------------------
// Dependencies used in the build
dependencies {
// This dependencies is exported to consumers, that is to say found on their compile classpath.
//-------------------------------------------------------------------------------------------------------------------
// Apache-commons
api "org.apache.commons:commons-lang3:3.7"
api "org.apache.commons:commons-text:1.2"
api "org.apache.commons:commons-collections4:4.1"
api "commons-io:commons-io:2.6"
api "commons-codec:commons-codec:1.11"
// JSON / XML processing
api "com.fasterxml.jackson.core:jackson-core:2.9.4"
api "com.fasterxml.jackson.core:jackson-databind:2.9.4"
// Better HJSON handling
api "org.hjson:hjson:3.0.0"
// http client support
api 'com.squareup.okhttp3:okhttp:3.10.0'
// Servlet API support
api 'javax.servlet:javax.servlet-api:4.0.1'
// https://crunchify.com/java-mailapi-example-send-an-email-via-gmail-smtp/
// https://stackoverflow.com/questions/22020533/javamail-api-from-maven/22021656
// but the last package 1.4.+ for javax.mail:javax.mail is in 2012 whereas com.sun.mail
// is updated 1.6.2 is in 2018
// Email broadcaster
api 'com.sun.mail:javax.mail:1.6.2'
// 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.squareup.okhttp3:mockwebserver:3.10.0'
}
//----------------------------------------------------------------
//
// 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 "org", "picoded.shade.org"
relocate "com", "picoded.shade.com"
relocate "okhttp3", "picoded.shade.okhttp3"
}
//
// 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 "org", "org"
relocate "com", "com"
relocate "okhttp3", "okhttp3"
}
// Define the equivalent of buildAll
// for the build process done by "gradle build"
artifacts {
archives fatJar
archives shadowJar
archives jar
}
//----------------------------------------------------------------
//
// Concurent test threads
//
//----------------------------------------------------------------
test {
// Setup test to run on parllel threads = to number of processors by default
if (project.hasProperty('maxParallelForks')) {
maxParallelForks = project.maxParallelForks as int;
} else {
// Lets optimize the test to run in parllel threads by default
if( (Runtime.runtime.availableProcessors()) <= 1 ) {
maxParallelForks = 1;
} else {
maxParallelForks = (Runtime.runtime.availableProcessors() - 1) 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, to skip command if its not needed
inputs.files(srcBeautify_inputFiles)
outputs.dir(srcBeautify_outputDir)
// The build formatter command
workingDir '.'
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 testAndBuildAll {
description = "Performs the full test suite, then build all 3 jars: jar, shadowJar, fatJar"
dependsOn jacocoTestReport
dependsOn buildAll
}