-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy pathbuild.gradle.kts
352 lines (289 loc) · 12.9 KB
/
build.gradle.kts
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
import groovy.lang.Closure
import org.akhikhl.gretty.GrettyExtension
import org.wisepersist.gradle.plugins.gwt.GwtCompileOptions
import org.wisepersist.gradle.plugins.gwt.GwtPluginExtension
import org.wisepersist.gradle.plugins.gwt.GwtSuperDevOptions
import org.wisepersist.gradle.plugins.gwt.Style
plugins {
kotlin("jvm") version "1.6.10"
id("application")
id("java")
id("idea")
id("java-library")
id("war")
// Creates fat JAR
id("com.github.johnrengelman.shadow") version "7.0.0"
id("org.wisepersist.gwt") version "1.1.12"
id("org.gretty") version "3.0.5"
id("com.github.ben-manes.versions") version "0.39.0"
}
extensions.findByName("buildScan")?.withGroovyBuilder {
setProperty("termsOfServiceUrl", "https://gradle.com/terms-of-service")
setProperty("termsOfServiceAgree", "yes")
}
idea.module.isDownloadSources = true
idea.module.isDownloadJavadoc = true
java.toolchain.languageVersion.set(JavaLanguageVersion.of(11))
// Required if using DominoMVP and annotations that generate code
sourceSets {
val main by getting
main.java.srcDirs("build/generated/sources/annotationProcessor/java/main")
}
// Required for shadow JAR but we don't use it. Can not be replaced with application.mainClass.set.
application.mainClassName = "not-necessary"
val gradleDependencyVersion = "7.2"
tasks.wrapper {
gradleVersion = gradleDependencyVersion
distributionType = Wrapper.DistributionType.ALL
}
repositories {
mavenCentral()
google()
// Required for AWS Lambda Servlet annotation processor
maven(url = "https://jitpack.io")
// Required for Gradle Tooling API
maven(url = "https://repo.gradle.org/gradle/libs-releases-local/")
}
tasks.distZip { enabled = false }
tasks.distTar { enabled = false }
tasks.shadowDistZip { enabled = false }
tasks.shadowDistTar { enabled = false }
val awsLambdaJavaCoreVersion = "1.2.1"
val awsLambdaJavaLog4j2Version = "1.2.0"
val jacksonVersion = "2.12.4"
val vavrVersion = "0.9.2"
val awsSdk2Version = "2.17.19"
val awsCdkVersion = "1.159.0"
val junitVersion = "4.13.2"
val jettyVersion = "9.4.40.v20210413"
val bouncyCastleVersion = "1.68"
val vertxVersion = "4.0.3"
val jjwtVersion = "3.15.0"
// NOTE: Versions newer than 0.16.8 will not work without modifications to this application
val awsCdkConstructsForJava = "0.16.8"
val awsLambdaServletVersion = "0.3.7"
val log4jVersion = "2.14.1"
val daggerVersion = "2.38.1"
val gwtVersion = "2.9.0"
val gwtServletVersion = gwtVersion
val gwtMaterialVersion = "2.4.2"
val gwtMaterialTempVersion = "2.4.2.1-temp"
val elemental2Version = "1.1.0"
val elementoVersion = "1.0.3"
val gwtJacksonVersion = "0.15.4"
val guavaGwtVersion = "30.1.1-jre"
val resultsIteratorForAwsJavaSdkVersion = "29.0.16"
val httpClientVersion = "4.5.13"
val hamcrestVersion = "2.2"
dependencies {
// Dagger code generation
annotationProcessor("com.google.dagger:dagger-compiler:$daggerVersion")
implementation("com.google.dagger:dagger:$daggerVersion")
implementation("com.google.dagger:dagger-gwt:$daggerVersion")
// Dependency added to fix - https://github.com/aws/aws-sdk-java-v2/issues/652
implementation("org.apache.httpcomponents:httpclient:$httpClientVersion")
implementation("software.amazon.awssdk:apache-client:$awsSdk2Version")
implementation("com.fasterxml.jackson.core:jackson-core:$jacksonVersion")
implementation("com.fasterxml.jackson.core:jackson-databind:$jacksonVersion")
implementation("com.fasterxml.jackson.core:jackson-annotations:$jacksonVersion")
implementation("io.vavr:vavr:$vavrVersion")
implementation("io.vavr:vavr-jackson:$vavrVersion")
implementation("io.vavr:vavr-gwt:$vavrVersion")
implementation("software.amazon.awssdk:iot:$awsSdk2Version")
implementation("software.amazon.awssdk:iotdataplane:$awsSdk2Version")
implementation("software.amazon.awssdk:sts:$awsSdk2Version")
implementation("software.amazon.awssdk:ssm:$awsSdk2Version")
implementation("software.amazon.awssdk:lambda:$awsSdk2Version")
implementation("software.amazon.awscdk:lambda:$awsCdkVersion")
implementation("com.google.gwt:gwt-servlet:$gwtServletVersion")
implementation("org.eclipse.jetty:jetty-servlet:$jettyVersion")
implementation("org.eclipse.jetty:jetty-server:$jettyVersion")
implementation("com.github.awslabs:results-iterator-for-aws-java-sdk:$resultsIteratorForAwsJavaSdkVersion")
// Lambda core and logging
implementation("com.amazonaws:aws-lambda-java-core:$awsLambdaJavaCoreVersion")
implementation("org.apache.logging.log4j:log4j-api:$log4jVersion")
implementation("org.apache.logging.log4j:log4j-core:$log4jVersion")
api("org.apache.logging.log4j:log4j-slf4j18-impl:$log4jVersion")
api("com.amazonaws:aws-lambda-java-log4j2:$awsLambdaJavaLog4j2Version")
api("com.github.aws-samples:aws-lambda-servlet:$awsLambdaServletVersion")
annotationProcessor("com.github.aws-samples:aws-lambda-servlet:$awsLambdaServletVersion")
implementation("com.github.aws-samples:aws-cdk-constructs-for-java:$awsCdkConstructsForJava")
annotationProcessor("com.github.aws-samples:aws-cdk-constructs-for-java:$awsCdkConstructsForJava")
testImplementation("junit:junit:$junitVersion")
implementation("com.github.gwtmaterialdesign:gwt-material:$gwtMaterialVersion")
implementation("com.github.gwtmaterialdesign:gwt-material-themes:$gwtMaterialVersion")
// GWT material addins includes GWT material jquery
implementation("com.github.gwtmaterialdesign:gwt-material-addins:$gwtMaterialVersion")
implementation("com.github.gwtmaterialdesign:gwt-material-table:$gwtMaterialVersion")
implementation("com.google.elemental2:elemental2-dom:$elemental2Version")
implementation("org.jboss.elemento:elemento-core:$elementoVersion")
implementation("com.github.nmorel.gwtjackson:gwt-jackson:$gwtJacksonVersion")
// For client side base64 encoding and decoding
implementation("com.google.guava:guava-gwt:$guavaGwtVersion")
testImplementation("org.hamcrest:hamcrest:$hamcrestVersion")
testImplementation("org.hamcrest:hamcrest-core:$hamcrestVersion")
}
configurations.all {
// Check for updates on changing dependencies at most every 10 minutes
resolutionStrategy.cacheChangingModulesFor(10, TimeUnit.MINUTES)
// Don't allow any configuration to use a broken version of HTTP client
resolutionStrategy.force("org.apache.httpcomponents:httpclient:4.5.13")
}
configurations.implementation {
// Fixes - Caused by: java.util.ServiceConfigurationError: org.apache.juli.logging.Log: org.eclipse.jetty.apache.jsp.JuliLog not a subtype
exclude("org.mortbay.jasper")
}
// Extension configuration
configure<GrettyExtension> {
// Supported values:
// "jetty7", "jetty8", "jetty9", "tomcat7", "tomcat8"
servletContainer = "jetty9.4"
}
configure<GwtPluginExtension> {
gwtVersion = gwtServletVersion
maxHeapSize = "2048M"
modules("awslabs.VendingMachine")
compiler(closureOf<GwtCompileOptions> {
localWorkers = 8
optimize = 9
maxHeapSize = "2048M"
// Set this value if you need to debug the generated source
style = Style.OBF
} as Closure<GwtCompileOptions>)
superDev(closureOf<GwtSuperDevOptions> {
noPrecompile = true
maxHeapSize = "2048M"
} as Closure<GwtSuperDevOptions>)
}
// Task configuration
val awsIotBrowserBundle = "aws-iot-sdk-browser-bundle-min.js"
val awsIotBrowserBundleRelativeDestination = "./src/main/webapp/" + awsIotBrowserBundle
val awsIotBrowserBundleAbsoluteDestination =
project.projectDir.absolutePath + "/" + awsIotBrowserBundleRelativeDestination
val copyBrowserBundle by tasks.registering(Exec::class) {
dependsOn += createDockerContainerForBrowserBundle
commandLine(
"docker",
"cp",
"aws-iot-device-sdk-js-container:/node_modules/aws-iot-device-sdk/browser/aws-iot-sdk-browser-bundle-min-uglifyjs.js",
awsIotBrowserBundleRelativeDestination
)
}
tasks.warTemplate {
if (!File(awsIotBrowserBundleAbsoluteDestination).exists()) {
// If we don't have the browser bundle we'll need to build and copy it before the war template task runs
dependsOn += copyBrowserBundle
}
}
tasks.war {
// Make sure GWT code is compiled before the war is generated
dependsOn += tasks.compileGwt
// Make sure the fixed keys are generated before the WAR
dependsOn += tasks.test
}
val validateDockerIsAvailable by tasks.registering(Exec::class) {
isIgnoreExitValue = true
commandLine("bash", "-c", "docker &> /dev/null")
doLast {
if (execResult!!.exitValue != 0) {
throw GradleException("Docker is required for this build")
}
}
}
val validateUserHasPermissionsToRunDocker by tasks.registering(Exec::class) {
isIgnoreExitValue = true
dependsOn += validateDockerIsAvailable
commandLine("bash", "-c", "docker ps &> /dev/null")
doLast {
if (execResult!!.exitValue != 0) {
throw GradleException(
"This user does not have permission to use Docker or Docker is not running. " +
"If you recently added this user to the Docker group try logging out and logging back in again. " +
"If you are still unable to run this script but can run 'docker ps' in your shell try killing any existing Gradle daemons that were started before the user was added to the Docker group."
)
}
}
}
val buildDockerImageForBrowserBundle by tasks.registering(Exec::class) {
isIgnoreExitValue = true
dependsOn += validateUserHasPermissionsToRunDocker
commandLine("docker", "build", "--target", "awsIotDeviceSdk", "-t", "aws-iot-device-sdk-js-build", ".")
doLast {
if (execResult!!.exitValue != 0) {
throw GradleException("The Docker build of the Javascript IoT device SDK failed")
}
}
}
val removeBrowserBundleContainerBefore by tasks.registering(Exec::class) {
isIgnoreExitValue = true
commandLine("docker", "rm", "-f", "aws-iot-device-sdk-js-container")
}
val createDockerContainerForBrowserBundle by tasks.registering(Exec::class) {
isIgnoreExitValue = true
dependsOn += buildDockerImageForBrowserBundle
dependsOn += removeBrowserBundleContainerBefore
commandLine(
"docker",
"create",
"-ti",
"--name",
"aws-iot-device-sdk-js-container",
"aws-iot-device-sdk-js-build:latest",
"bash"
)
doLast {
if (execResult!!.exitValue != 0) {
throw GradleException("Creating the container to extract the Javascript IoT device SDK failed")
}
}
}
tasks.shadowJar {
// To prevent broken log4j2 configurations - see https://stackoverflow.com/a/61475766
transform(com.github.jengelman.gradle.plugins.shadow.transformers.Log4j2PluginsCacheFileTransformer::class.java)
// Wait until the war is generated so we can get the files from its output directory
dependsOn += tasks.war
dependsOn += tasks.warTemplate
// Make sure the fixed keys are generated before the shadow JAR
dependsOn += tasks.test
// Get all of the GWT compiler output
inputs.files(fileTree("build/gwt/out"))
from("build/gwt/out")
// Get all of the static assets
inputs.files(fileTree("war"))
from("war")
// Exclude WEB-INF so we don't include a bunch of classes we don't need
exclude("WEB-INF")
dependencies {
// NOTE: Do not exclude the following dependencies or things will break
// - javax.servlet:.*
// - com.google.gwt:gwt-servlet:.*
exclude(dependency("org.gwtproject.i18n:.*"))
exclude(dependency("org.gwtproject.core:.*"))
exclude(dependency("org.gwtproject.editor:.*"))
exclude(dependency("org.gwtproject.timer:.*"))
exclude(dependency("org.gwtproject.event:.*"))
exclude(dependency("org.gwtproject.safehtml:.*"))
exclude(dependency("org.dominokit:.*"))
exclude(dependency("io.vertx:.*"))
exclude(dependency("net.sourceforge.htmlunit:.*"))
exclude(dependency("colt:.*"))
exclude(dependency("com.github.tdesjardins:.*"))
exclude(dependency("tapestry:.*"))
exclude(dependency("com.google.gwt:gwt-dev:.*"))
exclude(dependency("com.google.gwt:gwt-user:.*"))
exclude(dependency("net.sourceforge.cssparser:.*"))
exclude(dependency("com.ibm.icu:.*"))
exclude(dependency("javax.websocket:.*"))
exclude(dependency("org.glassfish:.*"))
// Removed dependencies from the results iterator that we don't need
exclude(dependency("software.amazon.awssdk:dynamodb:.*"))
exclude(dependency("software.amazon.awssdk:ec2:.*"))
exclude(dependency("software.amazon.awssdk:greengrass:.*"))
exclude(dependency("software.amazon.awssdk:greengrassv2:.*"))
}
isZip64 = true
}
task("synth", JavaExec::class) {
classpath = sourceSets["main"].runtimeClasspath
main = "com.awssamples.serverlessui.VendingMachineStack"
}