-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathbuild.gradle
224 lines (186 loc) · 6.95 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
group 'org.lavenderx'
version rootProject.version
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'org.springframework.boot:spring-boot-gradle-plugin:1.4.3.RELEASE'
classpath 'org.flywaydb:flyway-gradle-plugin:4.1.2'
classpath 'com.bmuschko:gradle-docker-plugin:3.0.6'
}
}
apply plugin: 'java'
apply plugin: 'application'
apply plugin: 'org.springframework.boot'
apply plugin: 'org.flywaydb.flyway'
apply plugin: 'com.bmuschko.docker-remote-api'
String profile = 'dev'
def serverPort = 'server.port'
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
configurations {
provided
// Use logback-slf4j instead of the Spring's commons-logging
all*.exclude group: 'commons-logging', module: 'commons-logging'
mybatisGenerator
}
sourceSets {
main {
compileClasspath += configurations.provided
runtimeClasspath += configurations.provided
}
test {
compileClasspath += configurations.provided
runtimeClasspath += configurations.provided
}
}
ext {
def props = new Properties()
file("src/main/resources/${profile}.properties").withInputStream {
props.load(it)
}
props.each {
project.extensions.add("$it.key", it.value)
}
props = new Properties()
file('src/main/resources/common-config.properties').withInputStream {
props.load(it)
}
props.each {
if ("$serverPort" == "$it.key") {
serverPort = it.value
}
}
logbackVersion = '1.1.7'
lombokVersion = '1.16.12'
jacksonVersion = '2.8.1'
aspectjVersion = '1.8.9'
springbootVersion = '1.4.3.RELEASE'
mysqlDriverVersion = '6.0.3'
mybatisVersion = '3.4.1'
mybatisSpringVersion = '1.3.0'
mybatisMapperVersion = '3.3.8'
mybatisGeneratorVersion = '1.3.3'
}
//flyway {
// url = project['jdbc.url']
// user = project['jdbc.username']
// password = project['jdbc.password']
// locations = ["filesystem:db/migration"]
//}
bootRun {
// ex: gradle bootRun -PjvmArgs="-Dspring.profiles.active=dev"
if (project.hasProperty('jvmArgs')) {
jvmArgs = project.jvmArgs.split("\\s+") as List
}
addResources = true
}
jar {
manifest {
attributes 'Implementation-Title': 'modern-java-web-scaffold-backend',
'Implementation-Version': project.version.toString().replaceFirst("-(?i)SNAPSHOT", ""),
'Main-Class': 'org.springframework.boot.loader.JarLauncher',
'Start-Class': 'org.lavenderx.WebAppBoot'
}
baseName = rootProject.name + '-' + project.name
zip64 = true
}
docker {
url = 'http://localhost:2375'
}
repositories {
mavenLocal()
mavenCentral()
jcenter()
}
dependencies {
compile "ch.qos.logback:logback-classic:$logbackVersion"
compile "org.projectlombok:lombok:$lombokVersion"
compile("org.springframework.boot:spring-boot-starter-web:$springbootVersion") {
exclude group: 'org.springframework.boot', module: 'spring-boot-starter-tomcat'
}
compile "org.springframework.boot:spring-boot-starter-undertow:$springbootVersion"
// compile "org.springframework.boot:spring-boot-starter-data-jpa:$springbootVersion"
compile "org.springframework.boot:spring-boot-devtools:$springbootVersion"
compile "org.mybatis:mybatis:$mybatisVersion"
compile "org.mybatis:mybatis-spring:$mybatisSpringVersion"
compile "tk.mybatis:mapper:$mybatisMapperVersion" // MyBatis3 Mapper(http://www.mybatis.tk/)
compile "mysql:mysql-connector-java:$mysqlDriverVersion"
compile 'com.zaxxer:HikariCP:2.6.0'
compile 'com.google.guava:guava:21.0'
compile 'io.jsonwebtoken:jjwt:0.6.0'
// For Spring Dependencies
compile 'org.slf4j:jcl-over-slf4j:1.7.21'
compile "org.aspectj:aspectjrt:$aspectjVersion"
compile "org.aspectj:aspectjweaver:$aspectjVersion"
compile "com.fasterxml.jackson.core:jackson-core:$jacksonVersion"
compile "com.fasterxml.jackson.core:jackson-databind:$jacksonVersion"
compile 'commons-fileupload:commons-fileupload:1.3.1'
provided 'javax.servlet:javax.servlet-api:3.1.0'
testCompile "org.springframework.boot:spring-boot-starter-test:$springbootVersion"
mybatisGenerator "mysql:mysql-connector-java:$mysqlDriverVersion"
mybatisGenerator "org.mybatis.generator:mybatis-generator-core:$mybatisGeneratorVersion"
mybatisGenerator "tk.mybatis:mapper:$mybatisMapperVersion"
}
import com.bmuschko.gradle.docker.tasks.image.DockerBuildImage
import com.bmuschko.gradle.docker.tasks.image.Dockerfile
task copyDistFiles(type: Copy) {
dependsOn build
from("build/libs/$rootProject.name-$project.name-$project.version" + ".jar") {
rename { String fileName ->
fileName.replace("-$project.version", "")
}
}
from 'src/main/docker'
into 'build/docker'
includeEmptyDirs = false
}
task createDockerfile(type: Dockerfile) {
dependsOn copyDistFiles
destFile = project.file('build/docker/Dockerfile')
from 'java:8-jre'
maintainer 'Zongzhi Bai "dolphineor@gmail.com"'
copyFile 'modern-java-web-scaffold-backend.jar', '/opt'
copyFile 'startup', '/'
runCommand 'chmod +x /startup'
exposePort "$serverPort".toInteger()
entryPoint '/startup'
}
task buildImage(type: DockerBuildImage) {
dependsOn createDockerfile
inputDir = createDockerfile.destFile.parentFile
tag = "lavenderx/$rootProject.name-$project.name:" + project.version.toString().replaceFirst("-(?i)SNAPSHOT", "")
}
task mybatisGenerate << {
ant.properties['targetProject'] = projectDir.path
ant.properties['driverClass'] = project['jdbc.driverClassName']
ant.properties['connectionURL'] = project['jdbc.url']
ant.properties['userId'] = project['jdbc.user']
ant.properties['password'] = project['jdbc.pass']
ant.properties['src_main_java'] = sourceSets.main.java.srcDirs[0].path
ant.properties['src_main_resources'] = sourceSets.main.resources.srcDirs[0].path
ant.properties['modelPackage'] = this.modelPackage
ant.properties['mapperPackage'] = this.mapperPackage
ant.properties['sqlMapperPackage'] = this.sqlMapperPackage
ant.taskdef(
name: 'mbgenerator',
classname: 'org.mybatis.generator.ant.GeneratorAntTask',
classpath: configurations.mybatisGenerator.asPath
)
ant.mbgenerator(overwrite: true, configfile: 'db/generatorConfig.xml', verbose: true) {
propertyset {
propertyref(name: 'targetProject')
propertyref(name: 'userId')
propertyref(name: 'driverClass')
propertyref(name: 'connectionURL')
propertyref(name: 'password')
propertyref(name: 'src_main_java')
propertyref(name: 'src_main_resources')
propertyref(name: 'modelPackage')
propertyref(name: 'mapperPackage')
propertyref(name: 'sqlMapperPackage')
}
}
}