-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle
127 lines (110 loc) · 3.26 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
plugins {
id 'java'
id 'checkstyle'
}
checkstyle {
// nothing to add here
}
repositories {
mavenCentral()
}
dependencies {
compile group: 'org.postgresql', name: 'postgresql', version: '42.+'
compile group: 'org.eclipse.jetty', name: 'jetty-servlet', version: '9.4.12.v20180830'
compile group: 'org.slf4j', name: 'slf4j-api', version: '1.+'
compile group: 'com.google.guava', name: 'guava', version: '28.1-jre'
runtime group: 'org.slf4j', name: 'slf4j-simple', version: '1.+'
testCompile group: 'junit', name: 'junit', version: '4.+'
}
configurations.all {
resolutionStrategy {
failOnVersionConflict()
}
}
// simple task for educational purposes - shows the dependencies real path
task printClasspath {
doLast {
configurations.compile.each { println it }
}
}
task copyRuntimeDependencies(type: Copy) {
into 'build/libs'
from configurations.runtime
}
// run ./gradlew dependencies to see the dependency graph
task pgPrms {
def url = System.getenv('JDBC_DATABASE_URL')
if (url == null || url.allWhitespace) {
url = 'jdbc:postgresql://localhost:5432/school?user=postgres&password=changeit'
println('no JDBC_DATABASE_URL environment variable found, using default value')
}
def uri = new URI(url.substring(5))
ext.host = uri.host
ext.port = uri.port
ext.db = uri.path.substring(1)
def queryMap = uri.query.tokenize('&')*.tokenize('=').collectEntries()
ext.user = queryMap.user
ext.password = queryMap.password
}
task startPostgres(type: Exec) {
dependsOn pgPrms
commandLine 'docker', 'run',
'--name', 'ls-postgres',
'-e', "POSTGRES_PASSWORD=$pgPrms.ext.password",
'-p', '5432:5432/tcp',
'-d', 'postgres'
}
task stopPostgres(type: Exec) {
commandLine 'docker', 'rm', '--force', 'ls-postgres'
}
String db = 'school'
task dropDb(type: Exec) {
dependsOn pgPrms
commandLine 'dropdb',
'--if-exists',
'-h', pgPrms.ext.host,
'-U', pgPrms.ext.user,
'-w', pgPrms.ext.db
ext.output = {
return standardOutput.toString()
}
environment PGPASSWORD: pgPrms.ext.password
}
task createDb(type: Exec) {
dependsOn pgPrms, dropDb
commandLine 'createdb',
'-h', pgPrms.ext.host,
'-U', pgPrms.ext.user,
'-w', db
ext.output = {
return standardOutput.toString()
}
environment PGPASSWORD: pgPrms.ext.password
}
task initSchema(type: Exec) {
dependsOn pgPrms, createDb
commandLine 'psql',
'-h', pgPrms.ext.host,
'-U', pgPrms.ext.user,
'-d', pgPrms.ext.db,
'-w',
'-f', 'src/test/sql/createSchema.sql'
ext.output = {
return standardOutput.toString()
}
environment PGPASSWORD: pgPrms.ext.password
}
task addData(type: Exec) {
dependsOn pgPrms, initSchema
commandLine 'psql',
'-h', pgPrms.ext.host,
'-U', pgPrms.ext.user,
'-d', pgPrms.ext.db,
'-w',
'-f', 'src/test/sql/addData.sql'
ext.output = {
return standardOutput.toString()
}
environment PGPASSWORD: pgPrms.ext.password
}
task stage(dependsOn: ['build', 'copyRuntimeDependencies'])