-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle
228 lines (180 loc) · 7.05 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
import groovy.json.JsonSlurper
import groovy.transform.Canonical
plugins {
id "io.spring.dependency-management" version "1.0.3.RELEASE" apply false
id 'com.diffplug.gradle.spotless' version '2.4.1' apply false
id 'net.ltgt.apt' version '0.13' apply false
id 'com.commercehub.cucumber-jvm' version '0.12' apply false
}
group 'com.amazonaws.blox'
version '0.1-SNAPSHOT'
description "Blox: Open Source schedulers for Amazon ECS"
allprojects {
apply plugin: 'com.diffplug.gradle.spotless'
repositories {
mavenCentral()
}
}
subprojects {
apply plugin: 'io.spring.dependency-management'
dependencyManagement {
imports {
mavenBom 'com.amazonaws:aws-java-sdk-bom:1.11.215'
mavenBom 'software.amazon.awssdk:bom:2.0.0-preview-4'
}
dependencies {
// The software.amazon.awssdk:bom incorrectly exports an old
// version of Mockito, so we have to override it to the version we
// want here:
dependency 'org.mockito:mockito-core:2.10+'
dependencySet(group: 'org.springframework', version: '4.3.10.RELEASE') {
entry 'spring-core'
entry 'spring-beans'
entry 'spring-context'
entry 'spring-test'
}
dependencySet(group: 'org.slf4j', version: '1.7.+') {
entry 'slf4j-api'
entry 'jcl-over-slf4j'
}
dependencySet(group: 'org.mapstruct', version: '1.2.0.CR2') {
entry 'mapstruct-jdk8'
entry 'mapstruct-processor'
}
// The AWS SDK v2 BOM is incorrectly pinning Cucumber to an
// old version, so we have to manually override the version
// of all Cucumber dependencies here, including the transitive
// dependency on cucumber-java from cucumber-java8.
dependencySet(group: 'info.cukes', version: '1.2.5') {
entry 'cucumber-core'
entry 'cucumber-java'
entry 'cucumber-java8'
entry 'cucumber-spring'
}
dependency 'org.projectlombok:lombok:1.16.18'
dependency 'org.apache.logging.log4j:log4j-slf4j-impl:2.8+'
}
}
}
def unformattedProjects = [
'frontend-service-client'
]
configure(subprojects.findAll { !unformattedProjects.contains(it.name) }) {
spotless {
java {
googleJavaFormat()
licenseHeaderFile rootProject.file('licenses/license-header.java')
}
}
}
wrapper {
gradleVersion = '4.3'
// The 'all' distribution includes files that allow IntelliJ to provide
// additional context information in build.gradle files:
distributionType = 'all'
}
class BloxStack {
@Canonical
class BloxProperty {
String name
String getPropertyName() { "blox.${name}" }
String description
Closure<String> defaultValue
String toString() {
isOverridden() ? BloxStack.this.project[propertyName] : defaultValue()
}
boolean isOverridden() {
BloxStack.this.project.hasProperty(propertyName)
}
String toDescription() {
"${description.padRight(25)} ${"(${propertyName})".padLeft(15)}: ${this} ${isOverridden() ? "" : "(default)"}"
}
}
Project project
String currentUser = System.getenv("USER")
BloxStack(Project project) {
this.project = project
}
def name = new BloxProperty("name", "Default resource name", { "blox-${prefix}-${region}"})
// TODO Changing the stage name requires regenerating the client, since the stage name is
// hard-coded there. We should contribute the ability to configure this to the
// SDK codegen project.
def stage = new BloxProperty("stage", "API Gateway stage", { "alpha" })
def prefix = new BloxProperty("prefix", "Stack prefix", { "${currentUser}-${stage}" })
def region = new BloxProperty("region", "AWS Region", { "us-west-2" })
def profile = new BloxProperty("profile", "AWS Credential Profile", { name })
def cfnStack = new BloxProperty("cfnStack", "Cloudformation stack name", { name })
def s3Bucket = new BloxProperty("s3Bucket", "Deployment S3 bucket name", { name })
String toPrettyString(int indent) {
def props = [name, stage, prefix, region, profile, cfnStack, s3Bucket]
return props.collect { "${' ' * indent}${it.toDescription()}" }.join("\n")
}
}
ext {
stack = new BloxStack(project)
awsCommand = "aws"
sdkZip = file("${buildDir}/java-sdk-${version}.zip")
swaggerVersion = "1.5.16"
}
task showStackConfig() {
group "help"
description "Display the names of AWS resources used for deployment"
doLast {
println "Blox deployment stack configuration:"
println()
println(stack.toPrettyString(2))
println()
println "To customize these values, modify ~/.gradle/gradle.properties to override the property listed."
println()
println "AWS CLI configuration for profile ${stack.profile}:"
exec {
commandLine aws("configure", "list")
}
}
}
def aws(... args) {
return [awsCommand, "--profile", stack.profile, "--region", stack.region, *args]
}
task downloadClient() {
group "codegen"
description "Download a new version of the SDK for the currently deployed stack."
def deployTask = tasks.getByPath(":frontend-service:deploy")
inputs.file deployTask
outputs.file sdkZip
doLast {
sdkZip.parentFile.mkdirs()
def parameters = [
"service.name=Blox",
"java.package-name=com.amazonaws.blox",
"java.build-system=gradle",
"java.group-id=${project.group}",
"java.artifact-id=frontend-service-client",
"java.artifact-version=${project.version}",
"flattenRequests=true",
"flattenResponses=true",
].join(",")
exec {
commandLine aws("apigateway", "get-sdk",
"--rest-api-id", project(":frontend-service").deployment.outputs["ApiId"],
"--stage-name", stack.stage,
"--sdk-type", "java",
"--parameters", parameters,
sdkZip)
}
}
}
task updateClient(type: Copy, dependsOn: downloadClient) {
group "codegen"
description "Unpack the client for the currently deployed stack into the blox-client subproject."
ext.tmpDir = file("${buildDir}/tmp/sdk")
from zipTree(sdkZip)
into tmpDir
// Replace the API id in the generated client with a fixed string
// Otherwise we get a diff every time the client is updated for a different stack, even if the code is identical.
def apiId = project(":frontend-service").deployment.outputs["ApiId"]
filter { line -> line.replaceAll(apiId, "ecs-blox") }
doLast {
file("frontend-service-client").deleteDir()
file("${tmpDir}/generated-code").renameTo(file("frontend-service-client"))
}
}