-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle
197 lines (175 loc) · 6.92 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
import java.nio.file.Files
import java.nio.file.Paths
buildscript {
ext.overridable = { prop, defaultVal ->
hasProperty(prop) ? getProperty(prop) : defaultVal
}
ext.exec = { cmd ->
cmd.execute().text.trim()
}
ext.versions = [ gmd: [:] ]
versions.gwt = "2.8.0"
versions.errai = "4.0.0.CR1"
versions.gmd.core = "2.0-rc3"
versions.gmd.jquery = "1.0-rc3"
versions.gmd.table = "1.0-rc3"
ext.gwt = [ modules: [:], dir: [:] ]
gwt.workers = "2"
gwt.log = overridable("gwtLog", "INFO")
gwt.modules.dev = "demo.errai.App"
gwt.modules.prod = "demo.errai.App"
gwt.dir.build = "${buildDir}/gwt"
gwt.dir.deps = "${gwt.dir.build}/deps"
gwt.dir.input = "${gwt.dir.build}/input"
gwt.dir.output = "${gwt.dir.build}/output"
gwt.dir.extra = "${gwt.dir.build}/extra"
gwt.dir.dev = "${gwt.dir.build}/dev"
gwt.dir.unitcache = "${gwt.dir.build}/unitcache"
ext.errai = [ dir: [:] ]
errai.dir.work = "${projectDir}/.errai"
errai.dir.build = "${buildDir}/errai"
errai.dir.output = "${errai.dir.build}/output"
ext.deploy = [ dir: [:] ]
deploy.dir.war = "${projectDir}/war"
deploy.dir.app = "${deploy.dir.war}/${name}.war"
}
apply plugin: "war"
apply plugin: "eclipse"
repositories {
mavenCentral()
}
dependencies {
providedCompile "com.google.gwt:gwt-user:$versions.gwt"
providedCompile "com.google.gwt:gwt-dev:$versions.gwt"
runtime "com.google.gwt:gwt-servlet:$versions.gwt"
compile "org.jboss.errai:errai-javaee-all:$versions.errai", { exclude group: "asm" }
compile "org.jboss.errai:errai-jboss-as-support:$versions.errai"
providedCompile "com.github.gwtmaterialdesign:gwt-material:$versions.gmd.core"
providedCompile "com.github.gwtmaterialdesign:gwt-material-addins:$versions.gmd.core"
providedCompile "com.github.gwtmaterialdesign:gwt-material-themes:$versions.gmd.core"
providedCompile "com.github.gwtmaterialdesign:gwt-material-jquery:$versions.gmd.jquery"
providedCompile "com.github.gwtmaterialdesign:gwt-material-table:$versions.gmd.table"
}
clean.doFirst {
delete errai.dir.work
delete deploy.dir.war
}
// [WINDOWS]
// A shell command has a limited maximum size.
// Deep dependency chains require large paths for gwt{Compiler,CodeServer}.
// Therefore, soft symbolic links are generated to all the dependencies.
// The output directory can then be added to the classpath.
// [NOTE]
// Soft symbolic links are used because Windows NTFS does not allow hard links
// to be removed when in use. Hard links cause build failures as the Gradle daemon keeps a
// reference to the files it copies. This blocks the deamon from overwriting them in a subsequent build.
// [WARNING]
// To create symbolic links in Windows, the shell needs to be run with administator privileges,
// _even_ if you're a user with administrator privileges.
task gwtDependencies() {
inputs.files configurations.compile
inputs.files configurations.providedCompile
outputs.dir gwt.dir.deps
doFirst { file(gwt.dir.deps).mkdirs() }
doLast {
def target = Paths.get(gwt.dir.deps)
def deps = configurations.compile.files + configurations.providedCompile.files
def valid = deps.collect { file -> createSymbolicLink(file.toPath(), target) }
// Remove dependencies which no longer exist. Having this avoids the need to depend on task
// "clear", but still correctly recognizes when dependencies have been removed and a
// recompile should be triggered.
fileTree(gwt.dir.deps).minus(valid).each { file ->
logger.debug("Removed unreferenced cached dependency: " + file)
delete file
}
}
}
def createSymbolicLink(def origin, def target) {
def fileName = origin.fileName
def link = target.resolve(fileName)
// [WARNING] dependencies with the same filename but different content will be skipped because of this.
if(!link.toFile().exists())
Files.createSymbolicLink(link, origin)
link.toFile()
}
// Merge GWT inputs (source, classes, resources) to ensure Errai required property files are picked
// up correctly, e.g. ErraiApp.propeties, and Errai generators are triggered.
task gwtClasses(type: Copy, dependsOn: classes) {
includeEmptyDirs false
from sourceSets.main.output.resourcesDir
from(sourceSets.main.java.srcDirs) {
include "**/**.gwt.xml"
include "**/client/**"
include "**/shared/**"
}
from(sourceSets.main.output.classesDir) {
include "**/client/**"
include "**/shared/**"
}
into gwt.dir.input
}
// [WINDOWS]
// The classpath closure of the JavaExec task can not be used, because it
// refuses to accept directory wildcards in Windows.
// This would generate a "Could not normalize path" error.
// Therefore, the classpath must be provided as a JVM argument using "--classpath"
def gwtClasspath() {
[gwt.dir.input, "${gwt.dir.deps}/*"].flatten().join(":")
}
task gwtCompile(type: JavaExec, dependsOn: [gwtClasses, gwtDependencies]) {
main = "com.google.gwt.dev.Compiler"
jvmArgs = ["-classpath", gwtClasspath()]
maxHeapSize = "1024M"
inputs.files(gwtClasses.destinationDir).skipWhenEmpty()
inputs.files gwt.dir.deps
outputs.dir gwt.dir.output
args = [
gwt.modules.prod,
"-war", gwt.dir.output,
"-logLevel", gwt.log,
"-localWorkers", gwt.workers,
"-failOnError",
"-generateJsInteropExports",
"-extra", gwt.dir.extra
].flatten()
// Avoid generated errai classes to be added to the build/classes folder
// which in turn would trigger a redundant recompile even when nothing changes.
// [NOTE] The generated classes need be added to the final WAR.
systemProperties["errai.server.classOutput"] = errai.dir.output
}
war.dependsOn gwtCompile
war {
includeEmptyDirs false
from gwt.dir.output // include GWT generated output files
from (errai.dir.output) { into "WEB-INF/classes" } // include Errai generated output files
rootSpec.exclude("**/client/**") // exclude GWT specific client-side java source code
}
task gwtDev(type: JavaExec, dependsOn: gwtCompile) {
main = "com.google.gwt.dev.codeserver.CodeServer"
jvmArgs = ["-classpath", gwtClasspath()]
doFirst { file(gwt.dir.dev).mkdirs() }
args = [
gwt.modules.dev,
"-logLevel", gwt.log,
"-launcherDir", deploy.dir.app,
"-workDir", gwt.dir.dev,
"-style", "Pretty",
"-generateJsInteropExports",
"-bindAddress", "0.0.0.0"
].flatten()
systemProperties["gwt.persistentunitcachedir"] = gwt.dir.unitcache
}
task redeploy(type: Copy, dependsOn: war) {
doFirst { file(deploy.dir.app).mkdirs() }
doFirst { delete deploy.dir.app }
into deploy.dir.app
with war
}
task stop {
doLast { exec("docker-compose -f src/main/docker/wildfly.yml down") }
}
task start(dependsOn: stop) {
doFirst { file(deploy.dir.app).mkdirs() }
doLast { exec("docker-compose -f src/main/docker/wildfly.yml up -d") }
finalizedBy redeploy
}