forked from alfio-event/alf.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle
428 lines (367 loc) · 14.9 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
import ch.digitalfondue.jfiveparse.HtmlSerializer
import ch.digitalfondue.jfiveparse.NodeMatcher
import ch.digitalfondue.jfiveparse.Parser
import ch.digitalfondue.jfiveparse.Selector
import org.apache.tools.ant.filters.ReplaceTokens
import java.nio.charset.StandardCharsets
import java.time.Year
import java.time.ZoneId
import java.time.ZonedDateTime
import java.time.format.DateTimeFormatter
buildscript {
dependencies {
classpath 'com.opentable.components:otj-pg-embedded:0.13.3'
classpath 'org.postgresql:postgresql:42.2.20'
//this is for processing the index.html at compile time
classpath "com.github.alfio-event:alf.io-public-frontend:$alfioPublicFrontendVersion"
classpath "ch.digitalfondue.jfiveparse:jfiveparse:0.9.0"
//
}
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
mavenCentral()
maven {
url "https://jitpack.io"
}
}
}
plugins {
id 'io.freefair.lombok' version '5.3.3.3'
id 'java'
id 'idea'
id 'org.kordamp.gradle.jacoco' version '0.45.0'
id 'com.github.ben-manes.versions' version '0.38.0'
id 'com.github.hierynomus.license' version '0.16.1'
id 'net.researchgate.release' version '2.8.1'
id 'org.springframework.boot' version '2.5.12'
id 'org.sonarqube' version '3.3'
id 'net.ltgt.errorprone' version '2.0.1'
id 'com.github.node-gradle.node' version '3.1.0'
}
apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'project-report'
//as pointed out by @facundofarias, we should validate minimum javac version
task validate {
//check JDK version
def javaVersion = JavaVersion.current()
if (!javaVersion.isJava11Compatible()) {
throw new GradleException("A Java JDK 11+ is required to build the project.")
}
}
def profile = project.hasProperty('profile') ? project.profile : 'dev'
ext {
// default settings
jettyPort = 8080
jettyHost = '0.0.0.0'
datasourceUrl = 'jdbc:postgresql://localhost:5432/alfio'
datasourceUsername = 'postgres'
datasourcePassword = 'password'
datasourceValidationQuery = 'SELECT 1'
//springProfilesActive = 'dev
//springProfilesActive = 'dev,demo'
springProfilesActive = 'dev'
port = "8080"
switch (profile) {
case 'docker-test':
datasourceUrl = 'jdbc:postgresql://0.0.0.0:5432/postgres'
datasourceUsername = 'postgres'
datasourcePassword = 'postgres'
datasourceValidationQuery = 'SELECT 1'
break
case 'travis':
project.springProfilesActive = 'travis'
break
}
}
configurations {
compileOnly
testCompileOnly
providedRuntime
providedCompile
}
repositories {
mavenLocal()
mavenCentral()
maven {
url "https://jitpack.io"
}
}
dependencies {
implementation "com.fasterxml.jackson.datatype:jackson-datatype-jsr310"
implementation 'com.auth0:java-jwt:3.19.0'
implementation "com.fasterxml.jackson.core:jackson-core"
implementation "com.fasterxml.jackson.core:jackson-databind"
implementation "org.springframework.boot:spring-boot-properties-migrator", {
exclude module : 'spring-boot-starter-logging'
}
implementation 'org.springframework.session:spring-session:1.3.5.RELEASE'
implementation "ch.digitalfondue.npjt-extra:npjt-extra:2.0.4"
implementation "com.samskivert:jmustache:1.15"
implementation "javax.mail:mail:1.5.0-b01"
implementation 'com.moodysalem:LatLongToTimezoneMaven:1.2'
/**/
implementation 'com.openhtmltopdf:openhtmltopdf-core:1.0.10'
implementation 'com.openhtmltopdf:openhtmltopdf-pdfbox:1.0.10'
implementation 'ch.digitalfondue.jfiveparse:jfiveparse:0.10.0'
/**/
implementation "com.google.zxing:core:3.4.1"
implementation "com.google.zxing:javase:3.4.1"
implementation "org.flywaydb:flyway-core"
implementation "org.postgresql:postgresql"
implementation "com.zaxxer:HikariCP"
/* https://www.lunasec.io/docs/blog/log4j-zero-day/ */
implementation "org.apache.logging.log4j:log4j-api:2.17.1"
implementation "org.apache.logging.log4j:log4j-core:2.17.1"
implementation "org.apache.logging.log4j:log4j-jul:2.17.1"
implementation "org.apache.logging.log4j:log4j-slf4j-impl:2.17.1"
/**/
implementation "com.stripe:stripe-java:20.50.0"
implementation 'com.paypal.sdk:checkout-sdk:1.0.5'
implementation 'com.google.code.gson:gson:2.9.0'
implementation 'com.fatboyindustrial.gson-javatime-serialisers:gson-javatime-serialisers:1.1.1', {
exclude module: 'gson'
}
implementation "org.apache.commons:commons-lang3:3.12.0"
implementation "org.apache.commons:commons-text:1.9"
implementation 'com.opencsv:opencsv:5.6'
implementation 'commons-codec:commons-codec:1.15'
implementation 'net.sf.biweekly:biweekly:0.6.6'
implementation 'com.atlassian.commonmark:commonmark:0.17.0'
implementation 'com.atlassian.commonmark:commonmark-ext-gfm-tables:0.17.0'
implementation 'com.ryantenney.passkit4j:passkit4j:2.0.1'
implementation 'com.github.ben-manes.caffeine:caffeine'
implementation 'com.github.scribejava:scribejava-core:5.0.0'
implementation 'ch.digitalfondue.vatchecker:vatchecker:1.5.0'
implementation 'ch.digitalfondue.basicxlsx:basicxlsx:0.5.1'
implementation 'org.imgscalr:imgscalr-lib:4.2'
implementation 'org.mozilla:rhino-runtime:1.7.13'
implementation "com.github.alfio-event:alf.io-public-frontend:$alfioPublicFrontendVersion"
compileOnly "javax.servlet:javax.servlet-api:4.0.1"
testImplementation "javax.servlet:javax.servlet-api:4.0.1"
testImplementation 'org.testcontainers:testcontainers:1.16.2'
testImplementation 'org.testcontainers:postgresql:1.16.2'
testImplementation 'org.testcontainers:junit-jupiter:1.16.2'
testImplementation "org.springframework.boot:spring-boot-starter-test", {
exclude module : 'spring-boot-starter-logging'
}
runtimeOnly "commons-fileupload:commons-fileupload:1.4"
implementation "org.springframework.boot:spring-boot-starter-web", {
exclude module : 'spring-boot-starter-logging'
exclude group: "org.springframework.boot", module: 'spring-boot-starter-tomcat'
exclude group: "org.hibernate.validator"
}
implementation "org.springframework.boot:spring-boot-starter-security", {
exclude module : 'spring-boot-starter-logging'
}
implementation "org.springframework.boot:spring-boot-starter-mail", {
exclude module : 'spring-boot-starter-logging'
}
implementation "org.springframework.boot:spring-boot@jar", {
exclude module : 'spring-boot-starter-logging'
}
implementation "org.springframework.boot:spring-boot-autoconfigure@jar", {
exclude module : 'spring-boot-starter-logging'
}
implementation "org.springframework.boot:spring-boot-starter-log4j2"
implementation "org.springframework.boot:spring-boot-starter-jetty", {
exclude group: "org.eclipse.jetty.websocket", module: "websocket-server"
exclude group: "org.eclipse.jetty.websocket", module:"javax-websocket-server-impl"
}
testImplementation "org.junit.jupiter:junit-jupiter-api"
testImplementation "org.junit.jupiter:junit-jupiter-engine"
testImplementation "org.junit.platform:junit-platform-engine"
providedCompile "org.springframework.boot:spring-boot-starter-jetty", {
exclude group: "org.eclipse.jetty.websocket", module: "websocket-server"
exclude group: "org.eclipse.jetty.websocket", module:"javax-websocket-server-impl"
exclude module : 'spring-boot-starter-logging'
}
providedRuntime "org.springframework.boot:spring-boot-starter-jetty", {
exclude group: "org.eclipse.jetty.websocket", module: "websocket-server"
exclude group: "org.eclipse.jetty.websocket", module:"javax-websocket-server-impl"
exclude module : 'spring-boot-starter-logging'
}
implementation "org.joda:joda-money:1.0.1"
testImplementation 'org.mock-server:mockserver-netty:5.11.2', {
exclude group: 'org.mozilla', module: 'rhino'
}
annotationProcessor "org.springframework.boot:spring-boot-configuration-processor"
testImplementation 'org.seleniumhq.selenium:selenium-java:4.1.1'
errorprone('com.google.errorprone:error_prone_core:2.4.0')
}
// -- license configuration
license {
header = rootProject.file('config/HEADER')
strictCheck = true
ignoreFailures = false
mapping {
java = 'JAVADOC_STYLE'
sql = 'DOUBLEDASHES_STYLE'
}
ext.year = '2014-'+Year.now().toString()
include '**/*.java'
include '**/*.sql'
}
sonarqube {
properties {
property 'sonar.host.url', 'https://sonarcloud.io'
property 'sonar.organization', 'alfio-event'
property 'sonar.projectKey', 'alfio-event_alf.io'
property 'sonar.login', System.getenv('SONARCLOUD_TOKEN')
}
}
processResources {
doLast {
final gradleProperties = new File((File) it.destinationDir, 'application.properties')
final properties = new Properties()
assert gradleProperties.file
gradleProperties.withReader { properties.load(it) }
properties['alfio.version'] = project.version
properties['alfio.build-ts'] = ZonedDateTime.now(ZoneId.of("UTC")).format(DateTimeFormatter.ISO_ZONED_DATE_TIME)
properties['alfio.frontend.version'] = alfioPublicFrontendVersion
gradleProperties.withWriter { properties.store(it, null) }
//
// alf.io public frontend: read index.html rewrite path for css/js
final resource = Thread.currentThread().getContextClassLoader().getResourceAsStream("META-INF/resources/webjars/alfio-public-frontend/$alfioPublicFrontendVersion/alfio-public-frontend/index.html")
final indexDoc = new Parser().parse(new InputStreamReader(resource, StandardCharsets.UTF_8))
final basePath = "webjars/alfio-public-frontend/$alfioPublicFrontendVersion/alfio-public-frontend/"
NodeMatcher scriptNodes = Selector.select().element("script").toMatcher()
indexDoc.getAllNodesMatching(scriptNodes).stream().forEach({
it.setAttribute("src", basePath + it.getAttribute("src"))
})
NodeMatcher cssNodes = Selector.select().element("link").attrValEq("rel", "stylesheet").toMatcher();
indexDoc.getAllNodesMatching(cssNodes).stream().forEach({
it.setAttribute("href", basePath + it.getAttribute("href"))
})
final alfioPublicIndex = new File((File) it.destinationDir, "alfio-public-frontend-index.html")
alfioPublicIndex.write(HtmlSerializer.serialize(indexDoc), "UTF-8", false)
}
}
compileTestJava {
options.errorprone.disable('UnusedVariable',
'MixedMutabilityReturnType',
'MissingOverride',
'ImmutableEnumChecker', // not too useful, as it does not take into account the actual value of the field
'AlmostJavadoc',
'MissingSummary',
'EscapedEntity',
'EmptyBlockTag'
)
}
compileJava {
options.compilerArgs = ['-Xlint:all,-serial,-processing']
// both checks are problematic with lombok code
options.errorprone.disable('UnusedVariable',
'MixedMutabilityReturnType',
'MissingOverride',
'ImmutableEnumChecker', // not too useful, as it does not take into account the actual value of the field
'AlmostJavadoc',
'MissingSummary',
'EscapedEntity',
'EmptyBlockTag'
)
}
compileJava.dependsOn(processResources)
//propagate the system properties to the tests
test {
useJUnitPlatform()
systemProperties = System.properties
systemProperties.remove("java.endorsed.dirs")
jvmArgs("--illegal-access=warn")
testLogging {
events "failed"
exceptionFormat "full"
info.events = ["failed"]
}
}
bootRun {
def externalConfig = new File("./custom.jvmargs")
def opts = []
opts += [
"-Dspring.profiles.active=${project.springProfilesActive}",
"-Ddatasource.url=${project.datasourceUrl}",
"-Ddatasource.username=${project.datasourceUsername}",
"-Ddatasource.password=${project.datasourcePassword}",
"-Dalfio.version=${project.version}",
"-Dalfio.build-ts=${ZonedDateTime.now(ZoneId.of("UTC")).format(DateTimeFormatter.ISO_ZONED_DATE_TIME)}",
"-Dalfio.frontend.version=$alfioPublicFrontendVersion"
]
if(externalConfig.exists()) {
opts += externalConfig.readLines()
}
jvmArgs = opts
mainClass = 'alfio.config.SpringBootLauncher'
}
bootWar {
mainClassName = 'alfio.config.SpringBootLauncher'
classifier = 'boot'
def bowerDir = "resources/bower_components"
def excludesFile = new File("./lib_exclude")
if(excludesFile.exists()) {
exclude(excludesFile.readLines().collect({ bowerDir + it }))
}
}
// -- code-coverage
jacoco {
toolVersion = '0.8.7'
}
jacocoTestReport {
group = 'Reporting'
description = 'Generate Jacoco coverage reports after running tests.'
additionalSourceDirs.from(project.files(sourceSets.main.allSource.srcDirs))
sourceDirectories.from(project.files(sourceSets.main.allSource.srcDirs))
classDirectories.from(project.files(sourceSets.main.output))
reports {
xml.enabled = true
csv.enabled = false
html.enabled = true
}
}
task dockerize(type: Copy) {
from 'src/main/dist/Dockerfile'
into "${buildDir}/dockerize"
filter(ReplaceTokens, tokens: [ALFIO_VERSION: project.version])
}
task distribution(type: Copy) {
from zipTree("${project.buildDir}/libs/alfio-${project.version}-boot.war")
into "${buildDir}/dockerize"
dependsOn build, dockerize
}
task clever(type: Copy) {
from new File(project.buildDir, "libs/alfio-${project.version}-boot.war")
rename(new Transformer<String, String>() {
@Override
String transform(String s) {
return "alfio-boot.war"
}
})
into "${project.buildDir}/clevercloud"
dependsOn build
}
release {
buildTasks = ['distribution']
git {
requireBranch = ''
pushToRemote = 'origin'
signTag = true
}
}
// see https://github.com/freefair/gradle-plugins/issues/31#issuecomment-475355674
// since we have a custom lombok.config configuration file, we disable automatic override
generateLombokConfig.enabled = false
// MJML email templates translations to HTML
node {
download = true
}
task mjmlToHtml( type: NodeTask, dependsOn: 'npmInstall' ) {
script = file( 'src/main/node/mjmlToHtml.js' )
}
// We build HTML templates from MJML source files and then save them under "build/generated/resources" in order to be
// included in the final artifact.
// TODO should we do the same for plaintext templates? See https://gist.github.com/brasilikum/3cd515bad5541ca6c76873faf10445c2
processResources.dependsOn(mjmlToHtml)
sourceSets.main.output.dir file("$buildDir/generated/resources"), builtBy: mjmlToHtml