forked from hank-cp/sbp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
370 lines (321 loc) · 12.7 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
def checkProperty(Project project, String propName) {
if (!project.hasProperty(propName)) return false
String prop = project.property(propName)
return prop != null && prop.length() > 0
}
def getPropertyOrElse(Project project, String propName, String alternative) {
if (!checkProperty(project, propName)) return alternative
return project.property(propName)
}
def isApplicationProject(String projectName) {
return projectName.startsWith('demo') \
&& !projectName.endsWith('-api') \
&& !projectName.endsWith('-shared') \
&& !projectName.endsWith('-security')
}
def isLibraryProject(String projectName) {
return projectName.startsWith('sbp-')
}
def isPluginProject(Project project) {
return project.hasProperty("plugin")
}
buildscript {
ext.springBootVersion = '2.2.0.RELEASE'
ext.lombokVersion = '1.18.8'
ext.pf4jVersion = '3.1.0'
repositories {
jcenter()
mavenCentral()
maven { url 'http://repo.spring.io/plugins-release' }
}
dependencies {
classpath "org.yaml:snakeyaml:1.19"
// classpath 'ch.raffael.markdown-doclet:markdown-doclet:1.4' // TODO this plugin is not worked since JDK 11
classpath "org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}"
}
}
plugins {
id 'idea'
id 'nu.studer.jooq' version '3.0.3' apply false
id 'org.flywaydb.flyway' version "5.2.4" apply false
}
//*************************************************************************
// IDEA
//*************************************************************************
idea {
module {
inheritOutputDirs = true
downloadSources = true
}
}
//*************************************************************************
// Sub Project Config
//*************************************************************************
subprojects {
repositories {
jcenter()
mavenCentral()
maven { url 'https://repo.spring.io/milestone' }
maven { url "https://jitpack.io" }
}
apply plugin: 'java'
apply plugin: 'io.spring.dependency-management'
// apply plugin: 'ch.raffael.markdown-doclet'
if (isApplicationProject(name)) {
apply plugin: 'application'
apply plugin: 'org.springframework.boot'
apply plugin: 'nu.studer.jooq'
apply plugin: 'org.flywaydb.flyway'
} else {
apply plugin: 'maven-publish'
apply plugin: 'signing'
}
//*************************************************************************
// Properties
//*************************************************************************
Properties localProp = new Properties()
try {
localProp.load(project.rootProject.file('local.properties').newDataInputStream())
} catch(Exception ignored) {}
for (String propKey in localProp.keys()) {
ext.set(propKey, localProp.get(propKey))
}
ext."signing.secretKeyRingFile" = rootProject.file('publish.gpg')
task setProperties {
doFirst {
project.ext.executable = "$project.name"
}
}
//*************************************************************************
// Compile & Assemble
//*************************************************************************
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
tasks.withType(AbstractCompile) {
options.encoding = 'UTF-8'
}
tasks.withType(Javadoc) {
options.encoding = 'UTF-8'
if(JavaVersion.current().isJava9Compatible()) {
options.addBooleanOption('html5', true)
}
}
jar {
manifest.attributes provider: 'gradle'
enabled true
doFirst {
archiveFileName = "$project.name-${archiveVersion.get()}.${archiveExtension.get()}"
}
}
test {
testLogging.showStandardStreams = true
workingDir = project.rootDir
testLogging {
events "failed"
exceptionFormat "short"
}
}
configurations {
localLibs
compile.extendsFrom(localLibs)
}
dependencies {
localLibs fileTree(dir: 'libs', include: '**')
implementation "org.projectlombok:lombok:${lombokVersion}"
annotationProcessor "org.projectlombok:lombok:${lombokVersion}"
annotationProcessor "org.pf4j:pf4j:${pf4jVersion}"
testAnnotationProcessor "org.projectlombok:lombok:${lombokVersion}"
testAnnotationProcessor "org.pf4j:pf4j:${pf4jVersion}"
}
//*************************************************************************
// Build Tasks
//*************************************************************************
task("buildApp") {
finalizedBy jar
}
//*************************************************************************
// Plugin
//*************************************************************************
if (isPluginProject(project)) {
Properties pluginProp = new Properties()
pluginProp.load(file('plugin.properties').newDataInputStream())
task buildPlugin(type: Jar) {
group 'build'
dependsOn build
manifest.attributes(
"Plugin-Id": pluginProp.get("plugin.id"),
"Plugin-Class": pluginProp.get("plugin.class"),
"Plugin-Version": pluginProp.get("plugin.version"),
"Plugin-Provider": pluginProp.get("plugin.provider"),
"Plugin-Dependencies": pluginProp.get("plugin.dependencies"))
from configurations.localLibs.asFileTree.files.collect { zipTree(it) } // flat all lib classes into a fat Jar
// from configurations.localLibs.asFileTree.files
with jar
doLast {
// Deploy built plugins...
}
}
task deployPluginToLocal(type: Copy) {
group 'build'
dependsOn buildPlugin
from "$buildDir/libs/"
into "$rootDir/path/to/plugins/${plugin}/"
}
}
//*************************************************************************
// Spring Boot
//*************************************************************************
dependencyManagement {
imports {
mavenBom org.springframework.boot.gradle.plugin.SpringBootPlugin.BOM_COORDINATES
}
}
if (isApplicationProject(name)) {
bootRun {
doFirst {
jvmArgs = ["-Dfile.encoding=UTF-8", "-Dserver.port=${http_port}"]
}
}
if (project.hasProperty("db.url")) {
//*************************************************************************
// Database Initialization
//*************************************************************************
task("doMigration") {
dependsOn processResources
doFirst {
println ">>>>>>>>>>> doing db_migration on ${project.'db.url'}"
flyway {
url = project.'db.url'
user = project.'db.user'
password = project.'db.password'
driver = project.'db.driver'
schemas = ["${project.'db.schema'}"]
baselineVersion = '0'
baselineOnMigrate = true
table = project.'db.migration.table'
locations = ["filesystem:$buildDir/resources/main/${project.'db.migration.location'}"]
}
}
finalizedBy flywayMigrate, flywayInfo
}
task("doDataMigration") {
dependsOn processResources
doFirst {
println ">>>>>>>>>>> do db_data migration on ${project.'db.url'}"
flyway {
url = project.'db.url'
user = project.'db.user'
password = project.'db.password'
driver = project.'db.driver'
schemas = ["${project.'db.schema'}"]
baselineOnMigrate = true
baselineVersion = '0'
table = project.'db.data.table'
locations = ["filesystem:$buildDir/resources/main/${project.'db.data.location'}"]
}
}
finalizedBy flywayMigrate, flywayInfo
}
jooq {
sbp(sourceSets.main) {
jdbc {
url = project.'db.url'
user = project.'db.user'
password = project.'db.password'
driver = project.'db.driver'
}
generator {
name = 'org.jooq.codegen.DefaultGenerator'
database {
name = 'org.jooq.meta.postgres.PostgresDatabase'
inputSchema = project.'db.schema'
includes = '.*'
excludes = '_.*'
forcedTypes {
forcedType {
userType = 'com.fasterxml.jackson.databind.JsonNode'
binding = 'demo.sbp.shared.PostgresJsonbBinding'
types = 'jsonb'
}
}
}
target {
packageName = project.'jooq.target.package'
}
}
}
}
}
} else if (isLibraryProject(name)) {
//*************************************************************************
// Maven
//*************************************************************************
task sourcesJar(type: Jar, dependsOn: classes) {
archiveClassifier.set('sources')
from sourceSets.main.allSource
}
task javadocJar(type: Jar, dependsOn: javadoc) {
archiveClassifier.set('javadoc')
from javadoc.destinationDir
}
artifacts {
archives jar
archives sourcesJar
archives javadocJar
}
group = 'org.laxture'
publishing {
publications {
mavenJava(MavenPublication) {
groupId = project.getGroup()
from components.java
artifact sourcesJar
artifact javadocJar
pom {
name = project.name
description = 'sbp introduce plugin oriented programming to Spring Boot'
url = 'https://github.com/hank-cp/sbp'
organization {
name = 'org.laxture'
url = 'https://laxture.org'
}
issueManagement {
system = 'GitHub'
url = 'https://github.com/hank-cp/sbp/issues'
}
license {
name = 'Apache License 3.0'
url = 'https://github.com/hank-cp/sbp/blob/master/LICENSE'
distribution = 'repo'
}
scm {
url = 'https://github.com/hank-cp/sbp'
connection = 'scm:git:git://github.com/hank-cp/sbp.git'
developerConnection = 'scm:git:ssh://[email protected]:hank-cp/sbp.git'
}
developers {
developer {
name = 'Hank CP'
email = '[email protected]'
}
}
}
repositories {
maven {
def snapshotsRepoUrl = "https://oss.sonatype.org/content/repositories/snapshots"
def stagingRepoUrl = "https://oss.sonatype.org/service/local/staging/deploy/maven2"
url = version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : stagingRepoUrl
credentials {
username getPropertyOrElse(project, 'sonatypeUsername', '')
password getPropertyOrElse(project, 'sonatypePassword', '')
}
}
}
}
}
}
signing {
sign publishing.publications.mavenJava
}
}
}