-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.gradle
223 lines (189 loc) · 6.63 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
import io.miret.etienne.gradle.sass.CompileSass
import org.yaml.snakeyaml.Yaml
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'org.yaml:snakeyaml:2.3'
}
}
plugins {
id 'org.springframework.boot' version '3.3.4'
id 'io.spring.dependency-management' version '1.1.6'
id 'java'
id 'com.gorylenko.gradle-git-properties' version '2.4.2'
id 'com.adarshr.test-logger' version '4.0.0'
id 'jacoco'
id "org.flywaydb.flyway" version "[9.+,10.0["
id 'io.miret.etienne.sass' version '1.5.1'
}
jacoco {
toolVersion = '0.8.10'
}
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
configurations.configureEach {
resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
}
def props = new Properties()
if (file(".env").exists()) {
file(".env").withInputStream { props.load(it) }
}
repositories {
maven {
url 'https://oss.sonatype.org/content/repositories/snapshots'
}
mavenCentral()
}
def profile = props.getProperty('SPRING_PROFILES_ACTIVE')
def formFlowLibraryVersion = '1.4.4-SNAPSHOT'
def useLocalLibrary = System.getenv('USE_LOCAL_LIBRARY')
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'ch.qos.logback.contrib:logback-json-classic:0.1.5'
implementation 'ch.qos.logback.contrib:logback-jackson:0.1.5'
if (profile == 'dev' || useLocalLibrary == 'true') {
implementation fileTree(dir: "$rootDir/../form-flow/build/libs", include: '*.jar')
println "📦 Using local library"
} else {
implementation "org.codeforamerica.platform:form-flow:${formFlowLibraryVersion}"
println "📚Using form flow library ${formFlowLibraryVersion}"
}
compileOnly 'org.projectlombok:lombok'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.security:spring-security-test'
testImplementation 'org.seleniumhq.selenium:selenium-java'
testImplementation 'io.percy:percy-java-selenium:2.1.0'
testImplementation 'org.awaitility:awaitility'
testImplementation 'org.apache.httpcomponents.client5:httpclient5:5.3.1'
testImplementation 'io.github.bonigarcia:webdrivermanager:5.9.2'
testImplementation 'com.h2database:h2'
runtimeOnly 'org.postgresql:postgresql'
}
springBoot {
buildInfo()
}
test {
finalizedBy jacocoTestReport
useJUnitPlatform()
}
jacocoTestReport {
reports {
xml.required = true
}
}
// -------------------------------------
// USWDS Tasks
// -------------------------------------
sass {
// Version of dart-sass: https://github.com/sass/dart-sass/releases
version = '1.69.3'
}
tasks.register('checkForNpm', Exec) {
group 'cfa-uswds'
description = 'Check if npm is accessible and install it if not.'
commandLine 'sh', './scripts/check_for_npm.sh'
}
tasks.register('npmInstall', Exec) {
group 'cfa-uswds'
description = 'Install frontend dependencies using npm.'
dependsOn 'checkForNpm'
commandLine 'npm', 'install'
}
tasks.register('moveNodeModulesToGenerated', Copy) {
group 'cfa-uswds'
description = 'Move Node Modules into Generated so that Spring Boot can use the assets.'
dependsOn 'npmInstall'
from 'node_modules'
into 'generated/main/resources/static'
finalizedBy(moveUSWDSImagesToGenerated)
}
tasks.register('moveUSWDSImagesToGenerated', Copy) {
group 'cfa-uswds'
description = 'Move USWDS images into generated folder for Spring Boot to use it.'
dependsOn 'moveNodeModulesToGenerated'
from 'node_modules/@uswds/uswds/dist/img'
into 'generated/main/resources/static/assets/css/img'
}
def sassConfiguration = { CompileSass task ->
// Load path
task.loadPath project.file("${projectDir}/generated/main/resources/static")
task.loadPath project.file("${projectDir}/generated/main/resources/static/@codeforamerica/uswds/packages")
task.loadPath project.file("${projectDir}/generated/main/resources/static/@uswds/uswds/packages")
// Set the output style:
// Possible values are “expanded” and “compressed”, default is “expanded”.
task.style = 'expanded'
// For now, do not load source maps
task.sourceMap = 'none'
// Source directory containing sass to compile:
task.sourceDir = project.file("${projectDir}/src/main/resources/static/assets/scss")
// Directory where to output generated CSS:
task.outputDir = project.file("${projectDir}/generated/main/resources/static/assets/css")
}
tasks.named('compileSass', CompileSass).configure { task ->
group 'cfa-uswds'
description = 'Compile Sass files into CSS.'
dependsOn 'moveNodeModulesToGenerated'
sassConfiguration(task)
}
tasks.register('compileJs', Exec) {
group 'cfa-uswds'
description = 'Compile CommonJS into JavaScript.'
dependsOn 'moveNodeModulesToGenerated'
commandLine 'npx', 'rollup', '--config', 'rollup.config.cjs'
}
tasks.register('watchCompileSass', CompileSass) { task ->
group 'cfa-uswds watch'
description = 'Infinite task to watch and recompile changes with SCSS.'
dependsOn installSass
sassConfiguration(task)
watch()
}
tasks.register('watchCompileJs', Exec) {
group 'cfa-uswds watch'
description = 'Infinite task to watch and recompile changes with JavaScript.'
dependsOn 'moveNodeModulesToGenerated'
commandLine 'npx', 'rollup', '--config', 'rollup.config.cjs', '--watch'
}
tasks.register('cleanGenerated') {
group 'cfa-uswds'
description = 'Delete the generated directory.'
doFirst {
delete "generated"
}
}
clean {
doFirst {
delete "generated"
delete "node_modules"
}
}
enum DesignSystem {
HONEYCRISP,
CFA_USWDS;
static DesignSystem fromString(String value) {
for (DesignSystem designSystem : values()) {
if (designSystem.name().replaceAll('_', '-').equalsIgnoreCase(value)) {
return designSystem;
}
}
throw new IllegalArgumentException("Unknown design system: " + value);
}
}
def applicationYaml = file('src/main/resources/application.yaml')
def applicationProps = new Yaml().load(applicationYaml.text)
def designSystemNameString = applicationProps.get('form-flow')?.get('design-system')?.get('name')
def designSystem = DesignSystem.fromString(designSystemNameString ?: 'HONEYCRISP')
println "🎨 Using design system: $designSystem"
processResources {
if (designSystem == DesignSystem.CFA_USWDS) {
dependsOn compileSass
dependsOn compileJs
}
}