-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.gradle
More file actions
137 lines (112 loc) · 5.33 KB
/
Copy pathbuild.gradle
File metadata and controls
137 lines (112 loc) · 5.33 KB
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
import org.yaml.snakeyaml.Yaml
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:2.0.5.RELEASE")
classpath group: 'org.yaml', name: 'snakeyaml', version: '1.23'
}
}
plugins {
id 'java'
id 'idea'
id "org.springframework.boot" version "2.1.3.RELEASE"
/*
The Spring Boot gradle plugin provides many convenient features:
https://docs.spring.io/spring-boot/docs/current/gradle-plugin/reference/html
It collects all the jars on the classpath and builds a single, runnable "uber-jar", which makes it more convenient to execute and transport your service.
It searches for the public static void main() method to flag as a runnable class.
It provides a built-in dependency resolver that sets the version number to match Spring Boot dependencies. You can override any version you wish, but it will default to Boot’s chosen set of versions.
*/
id "io.spring.dependency-management" version "1.0.7.RELEASE"
}
String appVersion = '1.2.0'
String appName = 'ga-rest-api'
group 'net.andreweast'
version appVersion
sourceCompatibility = 1.8
targetCompatibility = 1.8
bootJar {
baseName = appName
version = version
// Replace version within AWS Elastic Beanstalk config file, such that it will upload the correct JAR, See: https://stackoverflow.com/questions/17395787/how-to-replace-a-string-word-in-a-text-file-in-groovy#comment88039162_29393157
doFirst {
ant.replaceregexp(
file: '.elasticbeanstalk/config.yml',
match: 'ga-rest-api-\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}[-\\w]*\\.jar',
replace: "ga-rest-api-${appVersion}.jar"
)
ant.replaceregexp(
file: 'package.json',
match: '"version": "\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}[-\\w]*"',
replace: '"version": "' + appVersion + '"'
)
}
// bundle Elastic Beanstalk config files into the JAR
from('.ebextensions') {
include 'environmentvariables.config'
include 'securitygroup-addexisting.config'
into('.ebextensions')
}
inputs.files('.ebextensions') // Informs the JAR task that files in this directory should be considered inputs, thus the JAR must be rebuilt if they are modified
manifest {
attributes(
"Implementation-Title": appName,
"Implementation-Version": version
)
}
}
repositories {
mavenCentral()
// jcenter()
jcenter {
// Needed for springfox @Swagger2WebMvc: https://github.com/springfox/springfox/issues/2581#issuecomment-451769249
url "http://oss.jfrog.org/artifactory/oss-snapshot-local/"
}
}
// Ext (extra) properties added to the project. Can be accssed in other scopes as "project.ext.myVariable"
ext {
springStarterVersion = "2.1.3.RELEASE"
thymeleafSecurityVersion = '3.0.4.RELEASE'
postgresqlDriverVersion = '42.2.5'
springfoxVersion = '3.0.0-SNAPSHOT'
jsonpathVersion = '2.4.0'
lombokVersion = '1.18.6'
}
dependencies {
// Spring Boot REST API
compile group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: springStarterVersion
testCompile group: 'com.jayway.jsonpath', name: 'json-path', version: jsonpathVersion
// Spring frontend templating engine (Just used to launch React)
// See: https://www.baeldung.com/spring-boot-start
// See: https://spring.io/guides/gs/serving-web-content/
compile group: 'org.springframework.boot', name: 'spring-boot-starter-thymeleaf', version: springStarterVersion
compile group: 'org.thymeleaf.extras', name: 'thymeleaf-extras-springsecurity5', version: thymeleafSecurityVersion
// Spring Boot Database
compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-rest', version: springStarterVersion
compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa', version: springStarterVersion
compile group: 'org.postgresql', name: 'postgresql', version: postgresqlDriverVersion
compile group: 'org.projectlombok', name: 'lombok', version: lombokVersion
// Spring frontend communication
compile group: 'org.springframework.boot', name: 'spring-boot-starter-websocket', version: springStarterVersion
// Spring Boot Security
compile group: 'org.springframework.boot', name: 'spring-boot-starter-security', version: springStarterVersion
// Swagger REST API Documentation
compile group: 'io.springfox', name: 'springfox-swagger2', version: springfoxVersion
compile group: 'io.springfox', name: 'springfox-data-rest', version: springfoxVersion
compile group: 'io.springfox', name: 'springfox-swagger-ui', version: springfoxVersion
}
// For SpringBoot's bootRun that starts a server, load the .ebextensions YAML file as environmental variables first
bootRun {
doFirst {
def yamlFileContents = (".ebextensions/environmentvariables.config" as File).text
def envs = new Yaml().load(yamlFileContents)["option_settings"]["aws:elasticbeanstalk:application:environment"] as Map<String, String>
envs.each { key, value ->
systemProperty key, value // Gradle's idiom for System.setProperty()
if (key == "RDS_HOSTNAME") {
println "POSTGRESQL HOSTNAME: Will be connecting to database: ${value}"
}
}
}
}