-
Notifications
You must be signed in to change notification settings - Fork 17
/
build.gradle
425 lines (370 loc) · 14.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
buildscript {
repositories {
mavenCentral()
}
}
plugins {
id 'org.springframework.boot' version '2.2.2.RELEASE'
id "org.flywaydb.flyway" version "6.0.8"
id "org.sonarqube" version "3.3"
id "com.moowork.node" version "1.2.0"
id 'com.avast.gradle.docker-compose' version '0.8.10'
id "com.github.ben-manes.versions" version "0.20.0"
}
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'checkstyle'
apply plugin: 'jacoco'
apply plugin: 'pmd'
apply plugin: 'maven'
apply plugin: 'maven-publish'
apply plugin: 'signing'
ext {
ossrhUsername = System.getenv("OSSRH_USERNAME")
ossrhPassword = System.getenv("OSSRH_PASSWORD")
}
ext.set("signing.secretKeyRingFile", ".signing/secring.gpg")
ext.set("signing.keyId", System.getenv("SIGNING_KEYID"))
ext.set("signing.password", System.getenv("SIGNING_PASSWORD"))
group = serviceGroup
version = serviceVersion
archivesBaseName = rootProject.name
project.ext.buildTime = java.time.Instant.now().toString() // for versioning
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenCentral()
jcenter()
maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
}
dependencies {
compile "org.springframework.boot:spring-boot-starter-web"
compile "org.springframework.boot:spring-boot-starter-data-jpa"
compile "org.springframework.boot:spring-boot-starter-actuator"
compile 'org.springframework.boot:spring-boot-starter-data-redis'
compile 'org.javers:javers-spring-boot-starter-sql:2.8.1'
compile "org.projectlombok:lombok"
compile "org.postgresql:postgresql:42.0.0"
compile "org.springframework:spring-test"
compile "com.fasterxml.jackson.datatype:jackson-datatype-jsr310"
compile "com.fasterxml.jackson.datatype:jackson-datatype-hibernate5"
compile "org.springframework.boot:spring-boot-starter-security"
compile "org.springframework.security.oauth.boot:spring-security-oauth2-autoconfigure:2.2.2.RELEASE"
compile "org.slf4j:slf4j-ext"
compile 'org.webjars.npm:api-console:3.0.17'
compile 'org.apache.commons:commons-lang3'
compile 'org.apache.commons:commons-csv:1.4'
compile 'org.apache.commons:commons-collections4:4.1'
compile 'commons-io:commons-io:2.5'
compile 'redis.clients:jedis'
compile group: 'javax.interceptor', name: 'javax.interceptor-api', version: '1.2'
compile 'org.flywaydb:flyway-core'
compile 'org.openlmis:openlmis-service-util:3.0.0'
compile 'org.hibernate:hibernate-java8'
compile 'org.hibernate:hibernate-spatial:5.3.16.Final'
compile 'com.bedatadriven:jackson-datatype-jts:2.4'
compile group: 'net.sf.ehcache', name: 'ehcache'
compile group: 'org.hibernate', name: 'hibernate-ehcache'
compile 'org.joda:joda-money:0.12'
compile 'org.jadira.usertype:usertype.core:7.0.0.CR1'
compile 'net.sf.supercsv:super-csv:2.4.0'
compile 'net.sf.supercsv:super-csv-dozer:2.4.0'
compile 'io.craftsman:dozer-jdk8-support:1.0.6'
compile 'ca.uhn.hapi.fhir:hapi-fhir-client:3.7.0'
compile 'ca.uhn.hapi.fhir:hapi-fhir-structures-r4:3.7.0'
annotationProcessor 'org.projectlombok:lombok:1.18.22'
implementation 'org.togglz:togglz-spring-boot-starter:2.6.1.Final'
compile 'org.togglz:togglz-console:2.6.1.Final'
compile 'org.togglz:togglz-spring-security:2.6.1.Final'
compile 'org.togglz:togglz-redis:2.6.1.Final'
testCompile 'io.rest-assured:rest-assured'
testCompile 'io.rest-assured:json-schema-validator'
testCompile 'io.rest-assured:spring-mock-mvc'
testCompile "com.jayway.restassured:rest-assured:2.7.0"
testCompile "org.springframework.boot:spring-boot-starter-test"
testCompile "guru.nidi.raml:raml-tester:0.8.15"
testCompile "org.raml:raml-parser:0.8.37"
testCompile "junit:junit"
testCompile "org.powermock:powermock-api-mockito2:2.0.4"
testCompile "org.powermock:powermock-module-junit4:2.0.4"
testCompile "nl.jqno.equalsverifier:equalsverifier:2.4"
testCompile "be.joengenduvel.java.verifiers:to-string:1.0.2"
testCompile 'org.togglz:togglz-testing:2.6.1.Final'
testCompile 'org.togglz:togglz-junit:2.6.1.Final'
testCompile "com.github.tomakehurst:wiremock:2.22.0"
testCompile "com.github.stefanbirkner:system-rules:1.19.0"
testAnnotationProcessor 'org.projectlombok:lombok:1.18.22'
runtime fileTree(dir: '/extensions/', include: '*.jar')
}
idea {
project {
vcs = 'Git'
ipr.withXml { xmlFile ->
// enable 'Annotation Processors', source: https://gist.github.com/stephanos/8645809
xmlFile.asNode().component
.find { it.@name == 'CompilerConfiguration' }['annotationProcessing'][0]
.replaceNode {
annotationProcessing {
profile(default: true, name: 'Default', useClasspath: 'true', enabled: true)
}
}
}
}
module {
sourceDirs -= file('src/integration-test/java')
testSourceDirs += file('src/integration-test/java')
}
}
flyway {
url = "$System.env.DATABASE_URL"
user = "$System.env.POSTGRES_USER"
password = "$System.env.POSTGRES_PASSWORD"
schemas = ['referencedata']
sqlMigrationPrefix = ''
placeholderPrefix = '#['
placeholderSuffix = ']'
}
sourceSets {
integrationTest {
java {
compileClasspath += main.output + test.output
runtimeClasspath += main.output + test.output
annotationProcessorPath += main.output + test.output
annotationProcessorPath += sourceSets.test.runtimeClasspath
srcDir file('src/integration-test/java')
}
resources.srcDir file('src/integration-test/resources')
}
}
/*
* Checking for docker is a proxy for determining if docker-compose should be used
* to start needed services
*/
ext.checkForDocker = { ->
def result = exec {
def command = "command -v docker"
ignoreExitValue = true
executable "bash" args "-l", "-c", command
}
if (0 == result.getExitValue()) {
println "has Docker"
return true
} else {
println "Docker not found"
return false
}
}
/*
* Configures system and environment variables, for the given task, when said task is started
* with docker-compose plugin providing services.
*/
ext.configureForDockerCompose = { task ->
// source .env file for postgres username and password
def envProps = new Properties()
file('.env').withInputStream{ it -> envProps.load(it) }
def postgresUser = envProps.getProperty('POSTGRES_USER')
def postgresPass = envProps.getProperty('POSTGRES_PASSWORD')
task.environment "POSTGRES_USER", postgresUser
task. environment "POSTGRES_PASSWORD", postgresPass
// source log host and port from docker compose
def log = dockerCompose.servicesInfos.log.firstContainer
task.systemProperty 'log.host', log.host
task.systemProperty 'log.port', 12514
//task.systemProperty 'log.port', log.ports[514] this doesn't work yet https://github.com/avast/gradle-docker-compose-plugin/issues/176
// source postgres host and port from docker compose
def db = dockerCompose.servicesInfos.db.firstContainer
task.environment "DATABASE_URL", "jdbc:postgresql://${db.host}:${db.port}/open_lmis"
// source redis host and port from docker compose
def redis = dockerCompose.servicesInfos.redis.firstContainer
task.environment "REDIS_URL", redis.host
task.environment "REDIS_PORT", redis.ports[6379]
}
configurations {
integrationTestCompile.extendsFrom testCompile
integrationTestRuntime.extendsFrom testRuntime
}
dockerCompose {
stopContainers = false
}
task integrationTest(type: Test) {
testClassesDirs = sourceSets.integrationTest.output.classesDirs
classpath = sourceSets.integrationTest.runtimeClasspath
testLogging {
events "passed", "skipped", "failed"
exceptionFormat = 'full'
}
mustRunAfter test
environment 'BASE_URL', "http://localhost"
exclude '**/migration/**'
if (checkForDocker()) dockerCompose.isRequiredBy(integrationTest)
doFirst {
if(checkForDocker()) {
configureForDockerCompose(integrationTest)
}
}
}
tasks.withType(Test) {
reports.html.destination = file("${reporting.baseDir}/${name}")
reports.junitXml.destination = file("${testResultsDir}/${name}")
}
// Usage: gradle generateMigration [-PmigrationName=name_of_migration]
// Defaults to 'migration' as migration name
// Example: gradle generateMigration -PmigrationName=add_column_to_users
// Will create a file in migration folder with name yyyyMMddHHmmssSSS_add_column_to_users.sql.
task generateMigration {
description 'Creates an empty new file within the src/main/resources/db/migration directory into which developers can add new SQL migration code.'
doLast {
def fileName = project.hasProperty('migrationName') ? migrationName : 'migration'
def timestamp = new Date().format('yyyyMMddHHmmssSSS', TimeZone.getTimeZone('GMT'))
def fullFileName = "${timestamp}__${fileName}.sql"
def migrationFile = new File(sourceSets.main.resources.srcDirs.first(), 'db/migration/' + fullFileName)
migrationFile << "-- WHEN COMMITTING OR REVIEWING THIS FILE: Make sure that the timestamp in the file name (that serves as a version) is the latest timestamp, and that no new migration have been added in the meanwhile.\n"
migrationFile << "-- Adding migrations out of order may cause this migration to never execute or behave in an unexpected way.\n"
migrationFile << "-- Migrations should NOT BE EDITED. Add a new migration to apply changes."
migrationFile.createNewFile()
}
}
task checkApiIsRaml(type:Exec) {
executable "raml-cop"
args "src/main/resources/api-definition.yaml"
}
configure(checkApiIsRaml) {
group = JavaBasePlugin.VERIFICATION_GROUP
description = 'Verify that the api-specification is valid RAML'
}
test {
testLogging.showStandardStreams = false // set to true for verbose console output
maxParallelForks = Runtime.runtime.availableProcessors() - 1 ?: 1
testLogging {
events 'started', 'passed'
exceptionFormat = 'full'
}
dependsOn checkstyleMain
dependsOn checkstyleTest
dependsOn pmdMain
dependsOn pmdTest
}
jacocoTestReport {
group = "reporting"
description = "Generate Jacoco coverage reports after running tests."
reports {
xml.enabled true
html.enabled true
csv.enabled false
}
additionalSourceDirs(files(sourceSets.main.allJava.srcDirs))
}
checkstyle {
toolVersion = "8.12"
}
//NOTE: This plugin requires that this task be named 'sonarqube'. In fact, it is performing SonarCloud analysis.
sonarqube {
properties {
property "sonar.projectKey", "OpenLMIS_openlmis-referencedata"
property "sonar.organization", "openlmis"
property "sonar.host.url", "https://sonarcloud.io"
property "sonar.java.source", "17"
property "sonar.coverage.jacoco.xmlReportPaths", "./report.xml"
}
}
pmd {
toolVersion = '5.4.0'
consoleOutput= true
ignoreFailures = false
ruleSetFiles = files("config/pmd/ruleset.xml")
reportsDir = file("build/reports/pmd")
}
tasks.withType(Pmd){
reports {
xml.enabled true
html.enabled true
}
}
//enable the lines below if you need to debug spring running in docker
bootRun {
jvmArgs = ["-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005"]
}
signing {
sign configurations.archives
}
task javadocJar(type: Jar) {
classifier = 'javadoc'
from javadoc
}
task sourcesJar(type: Jar) {
classifier = 'sources'
from sourceSets.main.allSource
}
task execJar(type: Jar) {
classifier = 'exec'
from sourceSets.main.output
}
artifacts {
archives javadocJar, sourcesJar, execJar
//archives sourcesJar, execJar
}
signArchives.onlyIf {project.findProperty("signing.keyId") && project.findProperty("signing.password")}
uploadArchives {
repositories {
mavenDeployer {
beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") {
authentication(userName: ossrhUsername, password: ossrhPassword)
}
snapshotRepository(url: "https://oss.sonatype.org/content/repositories/snapshots/") {
authentication(userName: ossrhUsername, password: ossrhPassword)
}
pom.project {
name project.name
packaging 'jar'
description project.description()
url = 'https://openlmis.org'
licenses {
license {
name 'GNU Affero General Public License, Version 3'
url 'https://www.gnu.org/licenses/agpl-3.0.txt'
}
}
developers {
developer {
id = 'techcommittee'
name = 'tech committee'
email = '[email protected]'
organizationUrl = 'https://villagereach.org'
}
}
scm {
connection = 'scm:git:git://github.com/OpenLMIS/openlmis-referencedata.git'
developerConnection = 'scm:git:ssh://github.com/OpenLMIS/openlmis-referencedata' +
'.git'
url = 'http://github.com/OpenLMIS/openlmis-referencedata/'
}
}
}
}
}
uploadArchives.onlyIf { project.getProperty("ossrhUsername") && project.getProperty("ossrhPassword") }
apply from: "documentation.gradle"
integrationTest.dependsOn copyRamlToBuild
processResources {
finalizedBy npm_run_runApiHtmlConverter
// update version information in build
filesMatching('**/version.properties') {
expand(project.properties)
}
}
check {
finalizedBy uploadArchives
}
apply from: "registration.gradle"
assemble {
dependsOn npm_run_runApiHtmlConverter
dependsOn copyConsulRegistrationToBuild
dependsOn jacocoTestReport
}
build {
dependsOn check
dependsOn jacocoTestReport
}