forked from ichenkaihua/ssm-easy-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle
274 lines (200 loc) · 7.52 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
version '3.0'
apply plugin: 'war'
apply plugin: 'idea'
apply plugin: 'eclipse-wtp'
apply plugin: 'org.akhikhl.gretty'
apply plugin: 'org.flywaydb.flyway'
apply plugin: 'io.github.robwin.swagger2markup'
apply plugin: 'org.asciidoctor.convert'
//指定gradle wrapper版本
task wrapper(type: Wrapper) {
gradleVersion = '2.3'
}
configurations {
mybatisGenerator
}
//配置插件仓库
buildscript {
repositories {
mavenCentral()
jcenter()
}
dependencies {
classpath 'org.akhikhl.gretty:gretty:1.2.4'
classpath: 'mysql:mysql-connector-java:5.1.36'
classpath "org.flywaydb:flyway-gradle-plugin:4.1.2"
//swagger2markup
classpath 'io.github.robwin:swagger2markup-gradle-plugin:0.9.2'
classpath 'org.asciidoctor:asciidoctor-gradle-plugin:1.5.3'
//使用org.asciidoctor:asciidoctorj-pdf:1.5.0-alpha.15版本导致 class org.bouncycastle.asn1.ASN1Primitive overrides final method equals.(Ljava/lang/Object;)Z
classpath 'org.asciidoctor:asciidoctorj-pdf:1.5.0-alpha.11'
classpath 'io.github.robwin:swagger2markup-gradle-plugin:0.9.2'
}
}
//gretty设置
gretty {
port = 8080
contextPath = "/"
}
ext {
if (!project.hasProperty("env")) {
println '没有配置数据环境,默认使用 开发环境'
env = "dev"
}
println "使用数据库环境为:${project['env']}"
asciiDocOutputDir = file("${buildDir}/asciidoc")
println asciiDocOutputDir.absolutePath
swaggerOutputDir = file("${buildDir}/swagger")
println swaggerOutputDir.absolutePath
}
def getDbProperties = {
def properties = new Properties()
def dbPropertiesPath = sourceSets.main.resources.srcDirs[1].path;
file("$dbPropertiesPath/jdbc-mysql.properties").withInputStream { inputStream ->
properties.load(inputStream)
}
properties;
}
war{
archiveName="${baseName}-${project.version}.${extension}"
}
sourceSets {
main {
resources {
srcDir("src/main/resources")
if (project['env'] == 'dev') {
srcDir("src/main/resources-dev")
} else if (project['env'] == 'prod') {
srcDir('src/main/resources-prod')
}
}
}
}
test {
systemProperty 'io.springfox.staticdocs.outputDir', swaggerOutputDir
}
convertSwagger2markup {
dependsOn clean,test
inputDir swaggerOutputDir
examplesDir asciiDocOutputDir
pathsGroupedBy io.github.robwin.swagger2markup.GroupBy.TAGS
}
asciidoctor {
dependsOn convertSwagger2markup
//指定asciidoctorj版本
this.version='1.5.4'
sources {
include 'index.adoc'
}
backends = ['html5', 'pdf']
attributes = [
doctype: 'book',
'source-highlighter': 'coderay',
toc: 'left',
toclevels: '3',
numbered: '',
sectlinks: '',
sectanchors: '',
hardbreaks: '',
generated: asciiDocOutputDir
]
}
flyway {
def prop = getDbProperties()
user = prop.getProperty('jdbc.user')
url = prop.getProperty('jdbc.url')
password = prop.getProperty('jdbc.pass')
locations = ["filesystem:db/migration"]
}
repositories {
mavenCentral()
maven {
url 'https://repo.spring.io/libs-milestone'
}
}
//统一编码为utf-8
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
//依赖
dependencies {
testCompile 'com.jayway.restassured:rest-assured:2.9.0'
testCompile group: 'junit', name: 'junit', version: '4.12'
testCompile 'org.springframework:spring-test:4.3.7.RELEASE'
testCompile 'org.hamcrest:hamcrest-core:1.3'
testCompile 'org.mockito:mockito-core:1.10.19'
testCompile 'com.jayway.restassured:json-schema-validator:2.9.0'
testCompile 'com.jayway.restassured:spring-mock-mvc:2.9.0'
testCompile "org.springframework.restdocs:spring-restdocs-restassured:1.1.0.RC1"
//maven仓库中心没有的jar,则放入libs目录下
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'org.springframework:spring-webmvc:4.3.7.RELEASE'
compile 'org.springframework:spring-orm:4.3.7.RELEASE'
compile 'org.springframework:spring-context-support:4.3.7.RELEASE'
compile 'mysql:mysql-connector-java:6.0.6'
compile 'org.mybatis:mybatis:3.4.2'
compile 'org.mybatis:mybatis-spring:1.3.1'
compile 'com.github.pagehelper:pagehelper:5.0.0'
compile 'org.apache.shiro:shiro-spring:1.3.2'
compile 'org.apache.shiro:shiro-web:1.3.2'
compile 'org.apache.tomcat:tomcat-jdbc:8.5.12'
compile 'javax.mail:mail:1.4.7'
compile 'com.fasterxml.jackson.core:jackson-databind:2.8.7'
compile 'org.aspectj:aspectjweaver:1.8.10'
compile 'commons-fileupload:commons-fileupload:1.3.2'
compile 'org.slf4j:slf4j-log4j12:1.7.25'
compile 'tk.mybatis:mapper:3.4.0'
providedCompile 'javax.servlet:javax.servlet-api:3.1.0'
compile 'com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.8.7'
//swagger
compile "io.springfox:springfox-swagger2:2.6.1"
compile 'io.springfox:springfox-swagger-ui:2.6.1'
compile 'io.springfox:springfox-staticdocs:2.6.1'
//已下这些依赖有重复
compile 'com.github.fge:jackson-coreutils:1.8'
compile 'commons-codec:commons-codec:1.9'
compile 'com.googlecode.libphonenumber:libphonenumber:6.2'
compile 'com.google.code.findbugs:jsr305:3.0.0'
compile 'org.apache.httpcomponents:httpcore:4.4.3'
compile 'org.apache.commons:commons-lang3:3.3.2'
compile 'org.apache.httpcomponents:httpclient:4.5.1'
testCompile 'org.springframework.restdocs:spring-restdocs-mockmvc:1.1.2.RELEASE'
compile 'io.github.robwin:assertj-swagger:0.5.0'
testCompile 'com.fasterxml.jackson.module:jackson-module-jsonSchema:2.8.7'
mybatisGenerator 'org.mybatis.generator:mybatis-generator-core:1.3.5'
mybatisGenerator 'mysql:mysql-connector-java:6.0.6'
mybatisGenerator 'tk.mybatis:mapper:3.4.0'
}
task mybatisGenerate {
doLast {
def prop = getDbProperties()
ant.properties['targetProject'] = projectDir.path
ant.properties['driverClass'] = prop.getProperty('jdbc.driverClassName')
ant.properties['connectionURL'] = prop.getProperty('jdbc.url')
ant.properties['userId'] = prop.getProperty('jdbc.user')
ant.properties['password'] = prop.getProperty('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')
}
}
}
}