forked from oblac/jodd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
552 lines (455 loc) · 15.2 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
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
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
// Copyright (c) 2003-present, Jodd Team (http://jodd.org)
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
description = '''
Jodd is an open-source Java utility library and set of micro frameworks.
Jodd tools enriches JDK with many powerful and feature rich utilities.
It helps with everyday task, makes code more robust and reliable.
Jodd frameworks is set of lightweight application frameworks, compact yet powerful.
Designed following the CoC, DRY and SCS principles, it makes development
simple, but not simpler.
'''
version = '4.3.2-' + date()
//version = '4.3.1'
// --- properties -------------------------------------------------------------
ext {
gradleScriptDir = "${rootProject.projectDir}/gradle"
// libraries
tomcatVersion = '8.0.47'
jettyVersion = '9.3.21.v20170918'
jmhVersion = '1.20'
lib = [
mail: [
'javax.mail:javax.mail-api:1.6.1',
'com.sun.mail:javax.mail:1.6.1'
],
activation: 'javax.activation:activation:1.1.1',
servlet: 'javax.servlet:javax.servlet-api:3.1.0',
jsp: 'javax.servlet.jsp:javax.servlet.jsp-api:2.3.1',
log_slf4j: 'org.slf4j:slf4j-api:[1.7,1.8)',
log_slf4j_simple: 'org.slf4j:slf4j-simple:[1.7,1.8)',
log_logback_core: 'ch.qos.logback:logback-core:[1.2,1.3)',
log_logback_classic: 'ch.qos.logback:logback-classic:[1.2,1.3)',
log_jcl: 'commons-logging:commons-logging:[1.2,1.3)',
log_log4j2: 'org.apache.logging.log4j:log4j-api:[2.8,2.9)',
log_log4j2_core: 'org.apache.logging.log4j:log4j-core:[2.8,2.9)',
junit5: 'org.junit.jupiter:junit-jupiter-engine:5.0.3',
junit5_params: 'org.junit.jupiter:junit-jupiter-params:5.0.3',
junit5_console: 'org.junit.platform:junit-platform-console:1.0.2',
mockito: 'org.mockito:mockito-core:2.12.0',
hsqldb: 'org.hsqldb:hsqldb:2.2.9',
h2db: 'com.h2database:h2:1.1.111',
postgresql: 'org.postgresql:postgresql:9.4-1201-jdbc41',
mysql: 'mysql:mysql-connector-java:5.1.37',
mssql: 'com.microsoft.sqlserver:mssql-jdbc:6.1.0.jre8',
winstone: 'net.sourceforge.winstone:winstone:0.9.10',
greenmail: 'com.icegreen:greenmail:1.5.6',
el_api: "org.apache.tomcat:tomcat-jasper:${tomcatVersion}",
server_tomcat: "org.apache.tomcat:tomcat-catalina:${tomcatVersion}",
tomcat_embed: [
"org.apache.tomcat:tomcat-jasper:${tomcatVersion}",
"org.apache.tomcat:tomcat-jasper-el:${tomcatVersion}",
"org.apache.tomcat:tomcat-catalina:${tomcatVersion}",
"org.apache.tomcat.embed:tomcat-embed-core:${tomcatVersion}",
"org.apache.tomcat.embed:tomcat-embed-jasper:${tomcatVersion}",
"org.apache.tomcat.embed:tomcat-embed-logging-juli:${tomcatVersion}",
"org.apache.tomcat.embed:tomcat-embed-logging-log4j:${tomcatVersion}"
],
jetty_embed: [
"org.eclipse.jetty:jetty-server:${jettyVersion}",
"org.eclipse.jetty:jetty-webapp:${jettyVersion}",
"org.eclipse.jetty:jetty-jsp:9.2.23.v20171218"
],
mockserver: 'org.mock-server:mockserver-netty:5.1.1',
]
commonManifest = [
'Debug-Info' : 'on',
'Built-By' : 'jodd.org',
'Bundle-License' : 'https://jodd.org/license.html',
'Bundle-Vendor' : 'Jodd',
'Bundle-DocURL' : 'https://jodd.org',
'Implementation-Version': version,
'Implementation-Vendor': 'Jodd Team'
]
}
// --- modules sets -----------------------------------------------------------
allprojects {
version = rootProject.version
ext.isRelease = !version.contains("-")
ext.isSnapshot = !ext.isRelease
ext.isSubproject = project.parent != null
ext.isAdminRelease = ext.isRelease && project.hasProperty('JODD_ADMIN')
repositories {
mavenCentral()
}
}
def javaModules() {
subprojects.findAll {
it.name.contains('jodd-') &&
!it.name.equals('jodd-bom') &&
!it.name.equals('jodd-all')
}
}
def java9Modules() {
subprojects.findAll {
it.name.equals('jodd-core')
}
}
def javaBundleModules() {
rootProject.subprojects.findAll {
it.name.contains('jodd-') &&
!it.name.equals('jodd-joy') &&
!it.name.equals('jodd-bom') &&
!it.name.equals('jodd-all')
}
}
def javaMobileModules() {
rootProject.subprojects.findAll {
it.name.equals('jodd-core') ||
it.name.equals('jodd-bean') ||
it.name.equals('jodd-props')
}
}
// --- configuration ----------------------------------------------------------
apply plugin: 'idea'
apply plugin: 'eclipse'
// exclude folders from IDEA project
idea {
module {
excludeDirs += file('.idea')
}
}
configure(javaModules()) {
apply plugin: 'java'
apply plugin: 'jacoco'
apply plugin: 'osgi'
apply plugin: 'signing'
apply plugin: 'maven-publish'
apply plugin: 'idea'
apply plugin: 'eclipse'
apply from: "${gradleScriptDir}/provided.gradle"
apply from: "${gradleScriptDir}/publish-maven.gradle"
group = 'org.jodd'
// compile
compileJava {
sourceCompatibility = '1.8'
targetCompatibility = '1.8'
}
if (JavaVersion.current() < JavaVersion.VERSION_1_8) {
throw new GradleException("This build must be run with at least Java 8.")
}
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
options.compilerArgs << "-Xlint:-options"
// options.compilerArgs << "-Xlint:unchecked"
options.compilerArgs << "-Xlint:deprecation"
options.incremental = true
options.fork = true
}
tasks.withType(Javadoc) {
options.addStringOption('Xdoclint:none', '-quiet')
}
compileJava.options.debug = true
compileJava.options.fork = true
task sourcesJar(type: Jar, dependsOn: classes) {
classifier = 'sources'
from sourceSets.main.allSource
}
task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from javadoc.destinationDir
}
// integration tests + performances
sourceSets {
perf {
java {
compileClasspath += main.output
runtimeClasspath += main.output
}
}
testInt {
java {
compileClasspath += main.output
compileClasspath += test.output
runtimeClasspath += main.output
runtimeClasspath += test.output
}
}
}
configurations {
testIntCompile.extendsFrom testCompile
testIntRuntime.extendsFrom testRuntime
perfCompile.extendsFrom testCompile
perfRuntime.extendsFrom testRuntime
}
dependencies {
perfCompile "org.openjdk.jmh:jmh-core:${jmhVersion}"
perfCompile "org.openjdk.jmh:jmh-generator-annprocess:${jmhVersion}"
}
idea {
module {
// DONT: use separate output folders for idea, don't mess with gradle
inheritOutputDirs false
// see: https://youtrack.jetbrains.com/issue/IDEA-151925#comment=27-2356605
// since IDEA 2017.2.3
testSourceDirs += project.sourceSets.testInt.java.srcDirs
testSourceDirs += project.sourceSets.testInt.resources.srcDirs
}
}
task perf(type:JavaExec, dependsOn: 'compile') {
group 'Verification'
description 'Execute ALL benchmarks.'
main 'org.openjdk.jmh.Main'
classpath = sourceSets.perf.runtimeClasspath
}
tasks.addRule("Pattern: <ClassName>Benchmark : Run benchmark.") { String className ->
if (className.endsWith("Benchmark")) {
println "\nRunning Benchmark: " + className + "\n"
task "$className"(type: JavaExec, dependsOn: 'build') {
main 'org.openjdk.jmh.Main'
args = ['.' + className + '.*']
classpath = sourceSets.main.runtimeClasspath + sourceSets.perf.runtimeClasspath
}
}
}
task testUnit(type: JavaExec, dependsOn: compileTestJava) {
group 'Verification'
description 'Runs the unit tests.'
dependencies {
testRuntime lib.junit5_console
}
classpath = sourceSets.test.runtimeClasspath
main 'org.junit.platform.console.ConsoleLauncher'
args = ['--scan-classpath', sourceSets.test.output.classesDirs.asPath,
'--reports-dir', "${buildDir}/test-results/test"
]
}
test.dependsOn testUnit
task testIntegration(type: JavaExec, dependsOn: jar) {
group 'Verification'
description 'Runs the integration tests.'
dependencies {
testRuntime lib.junit5_console
}
classpath = sourceSets.testInt.runtimeClasspath
systemProperties['jar.path'] = jar.archivePath
main 'org.junit.platform.console.ConsoleLauncher'
args = ['--scan-classpath', sourceSets.testInt.output.classesDirs.asPath,
'--reports-dir', "${buildDir}/test-results/testInt"
]
}
afterEvaluate {
jacoco {
applyTo testUnit
applyTo testIntegration
}
testUnit.extensions.getByName("jacoco").excludes = ['*Test*', '*.?', '*Foo*', 'jodd.asm6.*', '*.fixtures.*', '*.JavaBridge']
testIntegration.extensions.getByName("jacoco").excludes = ['*Test*', '*.?', '*Foo*', 'jodd.asm6.*', '*.fixtures.*', '*.JavaBridge']
}
jacocoTestReport {
reports {
xml.enabled true
html.enabled true
}
}
task codeCoverage(type: JacocoReport) {
group 'Verification'
description 'Generates code coverage reports for a single module'
executionData fileTree("${buildDir}/jacoco/").include("*.exec")
//sourceSets sourceSets.main
sourceDirectories = sourceSets.main.java
classDirectories = sourceSets.main.output.classesDirs
reports {
html.enabled true
html.destination file("${buildDir}/reports/jacoco")
}
}
codeCoverage.dependsOn testUnit
codeCoverage.dependsOn testIntegration
//check.dependsOn testIntegration
//testIntegration.mustRunAfter test
// artifacts
artifacts {
archives jar
archives sourcesJar
archives javadocJar
}
jar {
afterEvaluate {
manifest.attributes << commonManifest
manifest {
name = project.moduleName
version = project.version
description = project.moduleDescription
attributes 'Implementation-Title': project.moduleName
}
}
}
javadoc {
exclude '**/asm6/**'
afterEvaluate {
configure(options) {
windowTitle 'Jodd API Documentation'
docTitle "$project.moduleName $project.version API Documentation"
bottom = 'Copyright © 2003-present <a href="http://jodd.org">Jodd Team</a>'
breakIterator = true
author = false
encoding = 'UTF-8'
docEncoding = 'UTF-8'
stylesheetFile = file('src/main/javadoc/jodd.css')
source = '1.8'
failOnError = false
}
}
}
}
configure (java9Modules()) {
apply from: "${gradleScriptDir}/jre9.gradle"
}
// --- project ----------------------------------------------------------------
apply plugin: 'project-report'
apply plugin: 'jacoco'
apply from: "${gradleScriptDir}/license.gradle"
def javaBundleModulesSources = javaBundleModules().sourceSets.main
task buildModules {
dependsOn javaModules().build
}
task testAll {
group 'Verification'
description 'Runs all the tests.'
dependsOn javaModules().testIntegration
dependsOn javaModules().test
}
task clean(type: Delete) {
group 'Project'
description 'Cleans everything.'
delete buildDir
}
task javadocAll(type: Javadoc) {
group 'Documentation'
description 'Builds the aggregated Java docs for all modules.'
dependsOn buildModules
maxMemory '512m'
source javaBundleModulesSources.allJava
exclude '**/asm6/**'
destinationDir = file("$buildDir/reports/javadoc")
classpath = files(javaBundleModulesSources.compileClasspath)
configure(options) {
windowTitle 'Jodd API Documentation'
docTitle "Jodd Project $project.version API Documentation"
bottom = 'Copyright © 2003-present <a href="http://jodd.org">Jodd Team</a>'
breakIterator = true
author = false
encoding = 'UTF-8'
docEncoding = 'UTF-8'
stylesheetFile = file('src/main/javadoc/jodd.css')
source = '1.8'
}
options.addStringOption('Xdoclint:none', '-quiet')
inputs.files(javaBundleModulesSources.allSource + javaBundleModulesSources.compileClasspath)
outputs.dir destinationDir
}
dependencyReport {
projects = javaModules()
}
task codeCoverageReport(type: JacocoReport) {
group 'Verification'
description 'Generates code coverage reports for the whole project'
executionData fileTree(project.rootDir.absolutePath).include("**/build/jacoco/*.exec")
jacocoClasspath
// workaround for making jacoco working on java9
FileCollection srcdirs = files()
FileCollection classdirs = files()
javaModules().each {
//sourceSets it.sourceSets.main
srcdirs += it.sourceSets.main.java
classdirs += it.sourceSets.main.output.classesDirs
}
sourceDirectories = srcdirs
classDirectories = classdirs
reports {
xml.enabled true
xml.destination file("${buildDir}/reports/jacoco/report.xml")
html.enabled true
csv.enabled false
}
}
codeCoverageReport.dependsOn testAll
// --- release ----------------------------------------------------------------
task release() {
group 'Project'
description 'Builds everything for the release.'
dependsOn buildModules
dependsOn testAll
dependsOn javadocAll
dependsOn ':distribution:build'
}
gradle.taskGraph.whenReady { taskGraph ->
if (taskGraph.hasTask(release)) {
println ""
println " You are about to run the 'release' task for Jodd project!"
println " This task builds distribution artifacts, but also runs"
println " integration tests and generates reports (javadoc, coverage...)"
println " For running integration tests you need infrastructure running;"
println " please find more information here: http://jodd.org/code.html"
println ""
println " Usually, you don't need to run this task. If you want to build"
println " distribution jars and run all unit tests, then just run the "
println " default 'build' task instead."
println ""
def char c
def console = System.console()
if (console) {
line = console.readLine(' > Do you want to continue? [y/N]: ')
line = line.trim()
c = line.charAt(0)
}
else {
println " > Do you want to continue? [y/N]: "
println ""
// Can't use `console` because it does not work with Gradle Daemon
def DataInputStream dis = new DataInputStream(System.in);
c = dis.readByte()
}
if (!(c == 'Y' || c == 'y')) {
throw new StopExecutionException("Execution terminated by user")
}
}
}
task version() {
println "-----------------------"
println " Jodd ${version}"
if (isSnapshot) println " [snapshot]"
println "-----------------------"
}
// --- util -------------------------------------------------------------------
def date() {
def date = new Date()
def formattedDate = date.format('yyyyMMdd')
return formattedDate
}
// --- wrapper ----------------------------------------------------------------
task wrapper(type: Wrapper) {
gradleVersion = '4.5'
}