/
build.gradle
503 lines (427 loc) · 22.4 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
/*
File : build.gradle
Purpose : Build file for the JasperReportsIntegration project on
Date Author Comment
--------------------------------------------------
08.09.2020 D. Aust initial creation
14.09.2020 D. Aust fixed script to be able to run on Windows as well, added some debug output.
15.09.2020 D. Aust - changed war file name from JasperReportsInegration.war to jri.war
- excluded the servlet-api*.jar files from the downloaded jasper libraries
18.09.2020 D. Aust added missing jasperreports.properties file to WEB-INF/classes
03.10.2020 D. Aust fixed bug in generating eclipse project file,
now it is back to using "bin/default" as the default output dir, should be "build"
07.10.2020 D. Aust #52 - Uptake JasperReports Library 6.15.0
07.10.2020 D. Aust #55 - Barcodes produce classnotfound error
17.11.2020 D. Aust #66 - Uptake JasperReports Library 6.15.0
#63 - Optimization for developers - adding your own .jar files
switch to version 2.7.0
14.12.2021 D. Aust #87 - Security warning: New zero-day in the Log4j Java library
16.12.2021 D. Aust Remove all spring* references, library not used and Vulnerable Library - spring-core-5.1.4.RELEASE.jar
31.01.2022 D. Aust Ignore/remove older log4j2 libraries included in jasperreports-libraries
31.01.2022 D. Aust #93: Upgrading log4j 1.x to log4j 2.x (2.17.1)
01.02.2022 D. Aust #70: Upgrade Oracle JDBC libraries
08.02.2022 D. Aust #82: Unable to start JRI with tomcat 10 - buildWarTomcat10 task created
02.06.2022 D. Aust #102: Upgrade libraries to JasperReports 6.19.1
24.08.2022 D. Aust #115: Upgrade libraries to JasperReports 6.20.0
25.08.2022 D. Aust #116: JDK17 support, replace Groovy library with 3.0.12 (3.0.+)
22.11.2023 D. Aust #136: Upgrade libraries to JasperReports 6.20.6
*/
plugins {
id "war"
id "eclipse"
id "distribution"
id "org.gretty" version "3.0.7"
}
// version 4.0 of gretty requires Java 11: https://gretty-gradle-plugin.github.io/gretty-doc/Gretty-configuration.html
//apply from: 'https://raw.github.com/gretty-gradle-plugin/gretty/master/pluginScripts/gretty.plugin'
//for Ant filter
import org.apache.tools.ant.filters.ReplaceTokens
import org.gradle.internal.os.OperatingSystem
// import groovy helper functions
// println "$project.projectDir/src/groovy/tools.groovy"
// evaluate(new File("$project.projectDir/src/groovy/tools.groovy"))
//-----------------------------------------------------------------------------
//-- Configuration: typically the JRI version and version of jasperreports
//-- are changed
//-----------------------------------------------------------------------------
project.description = "JasperReportsIntegration - more details here: https://github.com/daust/JasperReportsIntegration"
project.version = '2.11.0'
sourceCompatibility = 1.8
targetCompatibility = 1.8
archivesBaseName = "jri"
// version of jasperreports to be used
def jasperreportsVersion ='6.20.6'
// Download Oracle JDBC drivers, must be the full version:
// https://www.oracle.com/database/technologies/appdev/jdbc-ucp-19c-downloads.html
// put files into folder lib/additional-war-libraries
// Download JasperReports files from: https://sourceforge.net/projects/jasperreports/files/jasperreports/
// or from https://github.com/TIBCOSoftware/jasperreports/releases
//-----------------------------------------------------------------------------
//-- Groovy helper functions
//-----------------------------------------------------------------------------
/* define repositories to look for maven modules */
repositories {
maven {url "https://plugins.gradle.org/m2/"}
gradlePluginPortal()
maven {url "https://jaspersoft.jfrog.io/jaspersoft/third-party-ce-artifacts"}
mavenCentral()
flatDir {dirs "lib/jasper-reports/$jasperreportsVersion"}
}
/* define specific maven dependencies */
dependencies {
// *** Only for compilation, NOT distributed
//compileOnly 'javax.servlet:javax.servlet-api:3.1.0'
// https://mvnrepository.com/artifact/org.springframework/spring-core
implementation group: 'org.springframework', name: 'spring-core', version: '5.+'
// https://mvnrepository.com/artifact/org.springframework/spring-beans
implementation group: 'org.springframework', name: 'spring-beans', version: '5.+'
// https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-core
implementation group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.+'
// https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-jcl
implementation group: 'org.apache.logging.log4j', name: 'log4j-jcl', version: '2.+'
// https://mvnrepository.com/artifact/commons-configuration/commons-configuration
implementation group: 'commons-configuration', name: 'commons-configuration', version: '1.+'
// Get BOM file and choose Oracle JDBC driver (ojdbc8.jar) and Universal Connection Pool (ucp.jar)
// https://www.oracle.com/database/technologies/appdev/jdbc-downloads.html
// check the current version
implementation(enforcedPlatform("com.oracle.database.jdbc:ojdbc-bom:21.4.0.0.1"))
implementation("com.oracle.database.jdbc:ojdbc8")
implementation("com.oracle.database.jdbc:ucp")
// Additional Jars for using Oracle Wallets
implementation("com.oracle.database.security:oraclepki")
implementation("com.oracle.database.security:osdt_core")
implementation("com.oracle.database.security:osdt_cert")
// Additional Jars for High Availability
// ons removed due to Timeout issue when connecting to cloud database #69
// https://github.com/daust/JasperReportsIntegration/issues/69
//implementation("com.oracle.database.ha:ons")
implementation("com.oracle.database.ha:simplefan")
// encrypting PDF files: https://github.com/daust/JasperReportsIntegration/issues/101
// https://mvnrepository.com/artifact/org.bouncycastle/bcprov-jdk15on
implementation group: 'org.bouncycastle', name: 'bcprov-jdk15on', version: '1.70'
// https://mvnrepository.com/artifact/xalan/serializer
// see bug: #55 - Barcodes produce classnotfounderror
compile group: 'xalan', name: 'serializer', version: '2.7.1'
// https://mvnrepository.com/artifact/org.apache.xmlgraphics/xmlgraphics-commons
// see bug: #55 - Barcodes produce classnotfounderror
compile group: 'org.apache.xmlgraphics', name: 'xmlgraphics-commons', version: '2.+'
// *** Only for TESTING
testCompileOnly 'junit:junit:4.12'
// joda time because auf
// https://mvnrepository.com/artifact/joda-time/joda-time
compile group: 'joda-time', name: 'joda-time', version: '2.4'
// dependencies from jasperreports.proj
compile fileTree(dir: "lib/jasper-reports/$jasperreportsVersion", include: ['*.jar'])
// dependencies from oracle jdbc
compile fileTree(dir: "lib/additional-war-libraries", include: ['*'])
// https://mvnrepository.com/artifact/org.codehaus.groovy/groovy
implementation 'org.codehaus.groovy:groovy:3.0.+'
}
gretty {
servletContainer = 'tomcat9' // can be changed to Tomcat, by default jetty9 is used
httpPort = 8090
//initParameter 'oc.jasper.config.home', "/tmp/jri"
contextPath = "/jri"
jvmArgs = [
'-Xms2048m', //Xms4096m
'-Xmx2048m', //Xmx4096m
'-XX:+UseConcMarkSweepGC',
'-server',
'-Djava.awt.headless=true'
]
}
//-----------------------------------------------------------------------------
//-- Groovy helper functions
//-----------------------------------------------------------------------------
/* download the required libraries for jasperreports from the official repositories and
store them locally (also following redirect instructions) */
def downloadRedirect( String url, String filename ) {
while( url ) {
new URL( url ).openConnection().with { conn ->
conn.instanceFollowRedirects = false
url = conn.getHeaderField( "Location" )
if( !url ) {
new File( filename ).withOutputStream { out ->
conn.inputStream.with { inp ->
out << inp
inp.close()
}
}
}
}
}
}
/* download files without redirection */
def download(String remoteUrl, String localUrl) {
new File("$localUrl").withOutputStream { out ->
new URL(remoteUrl).withInputStream { from -> out << from; }
}
}
// a wrapper closure around executing a string
// can take either a string or a list of strings (for arguments with spaces)
// prints all output, complains and halts on error
def runCommand = { strList ->
def proc = strList.execute()
proc.in.eachLine { line -> println line }
proc.out.close()
proc.waitFor()
print "[INFO] ( "
if(strList instanceof List) {
strList.each { print "${it} " }
} else {
print strList
}
println " )"
if (proc.exitValue()) {
println "gave the following error: "
println "[ERROR] ${proc.getErrorStream()}"
}
assert !proc.exitValue()
}
// run os command dependent on OS
private static Iterable<String> osAdaptiveCommand(String... commands) {
def newCommands = []
if (OperatingSystem.current().isWindows()) {
newCommands = ['cmd', '/c']
}
newCommands.addAll(commands)
return newCommands
}
/* Eclipse configurations
see: https://docs.gradle.org/current/dsl/org.gradle.plugins.ide.eclipse.model.EclipseClasspath.html */
eclipse {
classpath {
// remove duplicate libraries from the build path. There is a conflict in Eclipse when duplicate libraries are on the build path
// one in the jasper build lib directory (lib/jasper-reports/$jasperreportsVersion) and the local gradle cache:
//
file {
whenMerged { classpath ->
java.util.List wanted = new java.util.ArrayList()
def entries = classpath.getEntries()
entries.each {
if ( (it.path.contains('commons-lang-2.6.jar') && it.path.contains('.gradle/caches'))
||
(it.path.contains('commons-logging-1.1.1.jar') && it.path.contains('.gradle/caches'))
) {
println('Removing library: ' + it.path + ' from eclipse classpath (duplicate)')
} else {
wanted.add(it)
}
}
classpath.setEntries(wanted)
}
}
//customizing the classes output directory => use /build instead of /bin
/*defaultOutputDir = file('build')
file.whenMerged {
entries.each { entry ->
if (entry.kind == 'src' && entry.hasProperty('output')) {
entry.output = entry.output.replace('bin/', "build/")
}
}
}
*/
//default settings for downloading sources and Javadoc:
downloadSources = true
downloadJavadoc = false
}
project {
resourceFilter {
appliesTo = 'FOLDERS'
type = 'EXCLUDE_ALL'
matcher {
id = 'org.eclipse.ui.ide.multiFilter'
// to find out which arguments to use, configure the desired
// filter with Eclipse's UI and copy the arguments string over
arguments = '1.0-projectRelativePath-matches-false-false-src/main/dist'
}
}
resourceFilter {
appliesTo = 'FOLDERS'
type = 'EXCLUDE_ALL'
matcher {
id = 'org.eclipse.ui.ide.multiFilter'
// to find out which arguments to use, configure the desired
// filter with Eclipse's UI and copy the arguments string over
arguments = '1.0-projectRelativePath-matches-false-false-src/doc'
}
}
}
}
//-----------------------------------------------------------------------------
//-- task definitions for JasperReportsIntegration
//-----------------------------------------------------------------------------
war {
dependsOn configurations.compile
archiveName = "${archivesBaseName}-${project.version}-jasper-${jasperreportsVersion}.war"
// replaces tokens in the respective files only for the assembly of the .war file:
// @project.version@ =>
// @jasperreports.version@ =>
filesMatching(["*.html", "*.jsp"]) {
filter(ReplaceTokens, tokens: ['project.version': project.version, 'jasperreports.version': jasperreportsVersion])
}
//from 'src/rootContent' // adds a file-set to the root of the archive
// all occurences of @project.version@ will be replaced with the current project version
//from('src/doc/User-Documentation'){
// into 'doc'
//filter(ReplaceTokens, tokens: ['project.version': project.version, 'jasperreports.version': jasperreportsVersion])
//}
from('src/conf'){
include 'jasperreports.properties' into 'WEB-INF/classes'
}
doFirst{
manifest {
attributes( "Implementation-Title": project.name,
"Implementation-Version": project.version,
"Main-Class": "main.CommandLine",
//"Class-Path": "*.jar"
//"Class-Path": configurations.runtimeClasspath.collect { it.getName() }.join(' ') + " " + jar.outputs.files.collect { it.getName() }.join(' ')
//"Class-Path": war.classpath.collect { it.getName() }.join(' ') + " " + jar.outputs.files.collect { it.getName() }.join(' ')
)
}
}
//webInf { from 'src/additionalWebInf' } // adds a file-set to the WEB-INF dir.
//classpath fileTree('additionalLibs') // adds a file-set to the WEB-INF/lib dir.
//classpath configurations.moreLibs // adds a configuration to the WEB-INF/lib dir.
//classpath = ['src/...',]
//classpath = war.classpath.plus('src/conf/jasperreports.properties')
//webXml = file('src/conf/web.xml') // copies a file to WEB-INF/web.xml
//webInf { from 'src/conf/weblogic.xml' } // adds a file-set to the WEB-INF dir.
}
distZip.setArchiveName("${archivesBaseName}-${project.version}-jasper-${jasperreportsVersion}.zip")
distTar.setArchiveName("${archivesBaseName}-${project.version}-jasper-${jasperreportsVersion}.tar")
distributions {
main {
distributionBaseName = 'JasperReportsIntegration'
println 'getName:' + Distribution.getName()
contents {
from('src/apex'){into 'apex'}
from('src/sql'){into 'sql'}
from('src/shell-scripts'){//exclude '*ConfigDir.*'
//exclude 'deploy*'
into 'bin'}
from('src/conf/application.properties'){into 'conf'}
from('src/conf/log4j2.xml'){into 'conf'}
//from('src/doc/User-Documentation'){into 'doc' filter(ReplaceTokens, tokens: ['project.version': project.version, 'jasperreports.version': jasperreportsVersion])}
from('src/doc/Documentation.html'){ filter(ReplaceTokens, tokens: ['project.version': project.version, 'jasperreports.version': jasperreportsVersion])}
from('src/reports'){into 'reports'}
from (war.outputs){into 'webapp' rename(war.archiveName , "jri.war")}
/*from (configurations.compile){
include(["commons-configuration-*.jar"
, "commons-lang-*.jar"
, "commons-logging-*.jar"
, "jasperreports-*.jar"])
into 'lib'
}*/
from ("lib/jasper-reports/$jasperreportsVersion"){include 'jasperreports*.jar' into 'lib'}
from (jar.outputs){into 'lib'}
from ('lib/additional-commandline-libraries'){into 'lib'}
// copy war file directly into jetty/webapps
// rather not, make zip distribution too large
//from (war.outputs){into 'jetty/webapps' rename(war.archiveName , "jri.war")}
}
}
}
println "\n***********************************************"
println "Version: " + project.version
println "Source-Compatibility: " + project.sourceCompatibility
println "Project description: " + project.property("description")
println "jasperreports version: " + jasperreportsVersion
println "War file name: " + war.archiveName // this will pick up the modified name defined in war{}
println "local environment OC_JASPER_CONFIG_HOME=" + System.getenv( "OC_JASPER_CONFIG_HOME")
println "***********************************************\n\n"
//-----------------------------------------------------------------------------
//-- task definitions for developers
//-- setting up the developer environment and downloading new JRI libraries
//-- for a new JasperReports release
//-----------------------------------------------------------------------------
/* create a local environment with configuration files and reports and logs for developers
Please register path in gradle.properties file */
task jriCreateLocalEnvironment{
description = "create a local environment with configuration files and reports and logs. Please register path in gradle.properties file"
doLast{
println "Create local developer environment at jriLocalPath=" + jriLocalPath
file(jriLocalPath).mkdirs()
copy{from ('src/reports') into "$jriLocalPath/reports"}
copy{from ('src/main/dist/logs') into "$jriLocalPath/logs"}
copy{from ('src/conf/application.properties') into "$jriLocalPath/conf"}
copy{from ('src/conf/log4j2.xml') into "$jriLocalPath/conf"}
}
}
task jriDownloadJasperLibraries{
description = "This will download the libraries for version $jasperreportsVersion to a local directory. Needs to be done only once when you upgrade to a new jasperreports version."
// ${File.separator}
doLast{
def tempLocation ="$project.projectDir/build/download/$jasperreportsVersion"
def tempLocation2 ="$tempLocation/jasperreports-$jasperreportsVersion"
def targetLocation ="$project.projectDir/lib/jasper-reports/$jasperreportsVersion"
def baseURLJasper ="https://sourceforge.net/projects/jasperreports/files/jasperreports/JasperReports%20${jasperreportsVersion}"
println " download files and install in target location: " + targetLocation
println " first download project files into temporary directory: " + tempLocation2
file(targetLocation).mkdirs()
file(tempLocation).mkdirs()
downloadRedirect( "$baseURLJasper/jasperreports-${jasperreportsVersion}-project.tar.gz", "$tempLocation/jasperreports.tar.gz")
downloadRedirect( "$baseURLJasper/jasperreports-chart-themes-${jasperreportsVersion}.jar", "$tempLocation/jasperreports-chart-themes-${jasperreportsVersion}.jar")
downloadRedirect( "$baseURLJasper/jasperreports-chart-customizers-${jasperreportsVersion}.jar", "$tempLocation/jasperreports-chart-customizers-${jasperreportsVersion}.jar")
downloadRedirect( "$baseURLJasper/jasperreports-functions-${jasperreportsVersion}.jar", "$tempLocation/jasperreports-functions-${jasperreportsVersion}.jar")
downloadRedirect( "$baseURLJasper/jasperreports-fonts-${jasperreportsVersion}.jar", "$tempLocation/jasperreports-fonts-${jasperreportsVersion}.jar")
// ungzip / untar files
copy {
from tarTree(resources.gzip("$tempLocation/jasperreports.tar.gz"))
into "$tempLocation"
}
// run build.xml file to download all libraries and build the jasperreport libraries
println "running ant task: " + osAdaptiveCommand("ant", "-f", "$tempLocation2/build.xml", "retrievelibs")
runCommand.call( osAdaptiveCommand("ant", "-f", "$tempLocation2/build.xml", "retrievelibs") )
println "running ant task: " + osAdaptiveCommand("ant", "-f", "$tempLocation2/build.xml", "jar")
runCommand.call( osAdaptiveCommand("ant", "-f", "$tempLocation2/build.xml", "jar") )
// copy all libraries to target location to: lib/jasper-reports/<version>
copy {
from "$tempLocation2"
from "$tempLocation2/dist"
from "$tempLocation2/dist/lib"
from "$tempLocation" // chart-customizers, chart-themes, jasperreports-functions, jasperreports-fonts
into "$targetLocation"
include "*.jar"
// exclude all that are used for compilation and test only
// but not required at runtime
exclude "net.tascalate.asmx*jar"
exclude "net.tascalate.javaflow*jar"
exclude "testng*jar"
exclude "servlet-api*"
// https://github.com/TIBCOSoftware/jasperreports/issues/241
// CVE-2021-22096 - Medium Severity Vulnerability, Vulnerable Library - spring-core-5.1.4.RELEASE.jar
exclude "spring-core-*"
exclude "spring-beans-*"
// ignore/remove older log4j2 libraries included in jasperreports-libraries
exclude "log4j-*"
exclude "groovy-3.0.*"
}
}
}
/* build a new war file that will work on Tomcat10 */
task buildWarTomcat10{
description = "build a new war file that will work on Tomcat10"
dependsOn build
//def cmd="$project.projectDir/src/build-support/jakartaee-migration-1.0.0/bin/migrate.sh $project.projectDir/build/distributions/${archivesBaseName}-${project.version}-jasper-${jasperreportsVersion}.zip $project.projectDir/build/distributions/${archivesBaseName}-${project.version}-jasper-${jasperreportsVersion}-tomcat10.zip -zipInMemory -exclude=\"*.jar\" -exclude=\"*jetty*.war\""
def cmd="$project.projectDir/src/build-support/jakartaee-migration-1.0.0/bin/migrate.sh $project.projectDir/build/libs/${archivesBaseName}-${project.version}-jasper-${jasperreportsVersion}.war $project.projectDir/build/distributions/${archivesBaseName}-${project.version}-jasper-${jasperreportsVersion}-tomcat10.war -zipInMemory -exclude=\"*.jar\" -exclude=\"*jetty*.war\""
doLast{
println "run command: " + cmd
runCommand.call( cmd )
}
}
/* build and deploy a version to the local Tomcat10 installation for testing */
task deployTomcat10{
description = "build a new war file that will work on Tomcat10"
//dependsOn buildWarTomcat10
def tomcatHome="/Users/daust/Downloads/KEEP/tomcat/apache-tomcat-10.0.16"
def cmd="cp $project.projectDir/build/distributions/${archivesBaseName}-${project.version}-jasper-${jasperreportsVersion}-tomcat10.war $tomcatHome/webapps/jri.war"
doLast{
println "shut down Tomcat10"
runCommand.call( "$tomcatHome/bin/shutdown.sh")
println "run command: " + cmd
runCommand.call( cmd )
println "start up Tomcat10"
runCommand.call( "$tomcatHome/bin/startup.sh")
}
}