Repository navigation
Expand file tree
/
Copy pathbuild.gradle
More file actions
190 lines (160 loc) · 6.56 KB
/
Copy pathbuild.gradle
File metadata and controls
190 lines (160 loc) · 6.56 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
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
import static java.lang.Boolean.parseBoolean
buildscript {
repositories {
mavenCentral()
maven {url = 'https://repo.grails.org/grails/restricted'}
}
dependencies { // Not Published to Gradle Plugin Portal
classpath platform("org.apache.grails:grails-bom:$grailsVersion")
classpath "org.apache.grails:grails-data-hibernate5"
classpath "org.apache.grails:grails-gradle-plugins"
}
dependencyLocking { lockAllConfigurations(); lockMode = LockMode.STRICT }
}
plugins {
id 'idea'
id 'war'
id 'co.uzzu.dotenv.gradle' version "$dotEnvGradlePluginVersion"
}
// Not Published to Gradle Plugin Portal
apply plugin: "org.apache.grails.gradle.grails-web"
version = xhAppVersion
group = xhAppPackage
repositories {
mavenCentral()
maven {url = 'https://repo.grails.org/grails/restricted'}
maven {url = 'https://central.sonatype.com/repository/maven-snapshots'}
}
configurations {
all {
// Ensure any SNAPSHOT dependencies are always resolved to the latest available version.
resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
}
}
// After changing a dependency, run: ./gradlew dependencies --write-locks -PrunHoistInline=false
// Locking applies to packaged builds only. An inline build takes its transitive graph from the
// local hoist-core checkout, which the lock state cannot track.
if (!parseBoolean(runHoistInline)) {
dependencyLocking {
lockAllConfigurations()
lockMode = LockMode.STRICT
}
}
springBoot {
mainClass = xhAppPackage + ".Application"
}
java {
toolchain {
languageVersion = JavaLanguageVersion.of(Integer.parseInt(majorJavaVersion))
}
}
def allJvmArgs = [
'-Dspring.output.ansi.enabled=always',
'-XX:TieredStopAtLevel=1',
'-XX:CICompilerCount=3',
'-Xmx' + localDevXmx,
"--add-exports=java.base/jdk.internal.ref=ALL-UNNAMED",
"--add-opens=java.base/java.lang=ALL-UNNAMED",
"--add-opens=java.base/sun.nio.ch=ALL-UNNAMED",
"--add-opens=java.management/sun.management=ALL-UNNAMED",
"--add-opens=jdk.management/com.sun.management.internal=ALL-UNNAMED",
"--add-opens=java.base/java.util=ALL-UNNAMED"
]
if (parseBoolean(enableHotSwap)) {
// Enhance JVM args, including Groovy Reset as agent
def groovyReset = configurations.detachedConfiguration(
dependencies.create("io.xh:groovyReset:1.0")
)
allJvmArgs += [
'-XX:HotswapAgent=fatjar',
'-XX:+AllowEnhancedClassRedefinition',
"-Dspring.devtools.restart.enabled=false",
"-Dspring.devtools.livereload.enabled=false",
"-javaagent:" + groovyReset.singleFile.absolutePath
]
}
dependencies {
// If `runHoistInline` is true, `hoistCoreVersion` will be ignored and local hoist-core will be used instead.
implementation "io.xh:hoist-core:$hoistCoreVersion"
// For server-side JWT validation.
implementation "org.bitbucket.b_c:jose4j:0.9.6"
// Database drivers - H2 for temporary in-memory DB with `useH2: true` in instanceConfig YAML
// MySQL for deployed instances, or more stateful local workstation setups.
runtimeOnly "com.h2database:h2"
runtimeOnly "com.mysql:mysql-connector-j:8.4.0"
// Stifle dev errors on Macs
developmentOnly "io.methvin:directory-watcher:0.19.1"
console "org.apache.grails:grails-console"
// Spock unit testing, via Hoist's test-support library - see hoist-core's docs/testing.md.
testImplementation "io.xh:hoist-core-test:$hoistCoreVersion"
}
tasks.withType(Test).configureEach { useJUnitPlatform() }
Map hoistMetaData = [
'info.xh.appCode': xhAppCode,
'info.xh.appName': xhAppName,
'info.xh.appPackage': xhAppPackage,
'info.xh.appBuild': findProperty('xhAppBuild') ?: 'UNKNOWN',
'info.xh.hoistReactVersion': new groovy.json.JsonSlurper()
.parse(file('client-app/package.json'))
.dependencies['@xh/hoist']
.replaceAll(/[\^~]/, '')
]
//-------------------------
// Trampoline jvmArgs
//-------------------------
// Properties that describe the daemon's own JDK install. Forwarding them to a forked toolchain
// JVM that runs a different JDK corrupts it - e.g. `java.home` makes the forked JVM resolve its
// internal modules against the wrong install, surfacing as `NoClassDefFoundError` on any code
// path that touches ICU (regex normalization, JCE init, java.text.Normalizer).
def jdkInstallProps = [
'java.class.path', 'java.class.version', 'java.home', 'java.library.path',
'java.runtime.name', 'java.runtime.version', 'java.specification.name',
'java.specification.vendor', 'java.specification.version',
'java.vendor', 'java.vendor.url', 'java.vendor.url.bug', 'java.vendor.version',
'java.version', 'java.version.date',
'java.vm.compressedOopsMode', 'java.vm.info', 'java.vm.name',
'java.vm.specification.name', 'java.vm.specification.vendor', 'java.vm.specification.version',
'java.vm.vendor', 'java.vm.version', 'jdk.debug'
] as Set
def execTasks = tasks.matching {it.name == 'bootRun' || it.name == 'console'}
execTasks.configureEach {
ignoreExitValue = true
// Forward daemon `-D` properties (e.g. `bootRun -Dserver.port=8081`) but skip the
// JDK-install descriptors above.
systemProperties System.properties.findAll { k, _ -> !jdkInstallProps.contains(k) }
jvmArgs(allJvmArgs)
systemProperties hoistMetaData
// Bring .env sourced environment variables into bootRun JVM process.
environment env.allVariables()
}
tasks.withType(GroovyCompile) {
configure(groovyOptions) {
forkOptions.jvmArgs = allJvmArgs
}
}
// Ask IntelliJ to download sources and javadocs for Gradle-managed dependencies.
idea {
module {
downloadJavadoc = true
downloadSources = true
}
}
//--------------------------------------------------
// Extensions to build.info (Hoist-Core requirement)
//--------------------------------------------------
tasks.war.doFirst {
File infoFile = layout.buildDirectory.file('resources/main/META-INF/grails.build.info').get().asFile
Properties properties = new Properties()
infoFile.withInputStream {properties.load(it)}
properties.putAll(hoistMetaData)
infoFile.withOutputStream {properties.store(it, null)}
}
// Ensure that all variables defined in .env.template are set in local .env
execTasks.all {task ->
task.doFirst {
def missingEnvVars = env.allVariablesOrNull().findAll { it.value == null }.collect { it.key }
if (missingEnvVars) {
throw new GradleException("Environment variables listed in .env.template not set in local .env file as required: ${missingEnvVars}")
}
}
}