-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathbuild.gradle
448 lines (364 loc) · 14.9 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
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
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
buildscript {
ext.kotlin_version = '1.2.71'
repositories {
if (rootProject.hasProperty('haulmontRepoUrl')) {
maven {
url rootProject['haulmontRepoUrl']
if (rootProject.hasProperty('haulmontRepoUser') && rootProject.hasProperty('haulmontRepoPassword')) {
credentials {
username rootProject['haulmontRepoUser']
password rootProject['haulmontRepoPassword']
}
}
}
} else {
jcenter()
maven {
url 'https://repo.cuba-platform.com/content/groups/work'
credentials {
username 'cuba'
password 'cuba123'
}
}
}
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
group 'com.haulmont.cuba.cli'
version rootProject.hasProperty('buildVersion') ? rootProject['buildVersion'] : '2.1-SNAPSHOT'
def apiVersion = 5
def moduleName = "com.haulmont.cuba.cli"
def velocityVersion = "1.7"
def jCommanderVersion = "1.72"
def jansiVersion = "1.17"
def guavaVersion = "26.0-jre"
def jlineVersion = "3.6.2"
def kodeinVersion = "5.0.0"
def practicalxmlVersion = "1.1.0"
def gsonVersion = "2.3.1"
apply plugin: 'kotlin'
apply plugin: 'maven'
apply plugin: 'application'
sourceCompatibility = 11
targetCompatibility = 11
repositories {
if (rootProject.hasProperty('haulmontRepoUrl')) {
maven {
url rootProject['haulmontRepoUrl']
if (rootProject.hasProperty('haulmontRepoUser') && rootProject.hasProperty('haulmontRepoPassword')) {
credentials {
username rootProject['haulmontRepoUser']
password rootProject['haulmontRepoPassword']
}
}
}
} else {
jcenter()
maven {
url 'https://repo.cuba-platform.com/content/groups/work'
credentials {
username 'cuba'
password 'cuba123'
}
}
}
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
implementation "com.beust:jcommander:$jCommanderVersion"
implementation "org.jline:jline:$jlineVersion"
implementation "org.fusesource.jansi:jansi:$jansiVersion"
implementation("org.apache.velocity:velocity:$velocityVersion") {
// jlink: org.apache.commons.lang.enum: Invalid package name: 'enum' is not a Java identifier
exclude(group: 'commons-lang', module: 'commons-lang')
}
// Using custom JAR without 'enum' package
implementation("commons-lang:commons-lang:2.4-cuba.0")
implementation("commons-collections:commons-collections:3.2.2")
implementation("com.google.guava:guava:$guavaVersion") {
exclude(group: 'com.google.code.findbugs', module: 'jsr305')
}
implementation("org.kodein.di:kodein-di-generic-jvm:$kodeinVersion") {
// jlink: org.apache.commons.lang.enum: Invalid package name: 'enum' is not a Java identifier
exclude(group: 'org.jetbrains.kotlin', module: 'kotlin-stdlib')
}
implementation("net.sf.practicalxml:practicalxml:$practicalxmlVersion") {
exclude(group: "junit", module: "junit")
}
implementation("com.google.code.gson:gson:$gsonVersion")
implementation("commons-configuration:commons-configuration:1.10") {
exclude(group: 'commons-lang', module: 'commons-lang')
}
implementation("commons-logging:commons-logging:1.1.1'")
testImplementation group: 'junit', name: 'junit', version: '4.12'
}
configurations {
compile {
exclude(group: 'org.jetbrains', module: 'annotations')
}
}
[compileKotlin, compileTestKotlin].each {
it.kotlinOptions.jvmTarget = '1.8'
}
processResources.doLast {
def buildProperties = new File(project.buildDir, 'resources/main/com/haulmont/cuba/cli/application.properties')
buildProperties.text = buildProperties.text.replace('version = DEVELOPMENT', 'version = ' + project.version)
}
compileJava {
inputs.property("moduleName", moduleName)
options.compilerArgs = [
'--module-path', classpath.asPath,
'--patch-module', 'com.haulmont.cuba.cli=' + compileKotlin.destinationDir
]
}
jar {
// do not permit duplicates in JAR
duplicatesStrategy = org.gradle.api.file.DuplicatesStrategy.FAIL
}
// disable automatic building of ZIP and TAR
configurations.archives.artifacts.removeAll {
it.file =~ 'tar' || it.file =~ 'zip'
}
task sourceJar(type: Jar) {
from file('src/main/java')
from file('src/main/kotlin')
from file('src/main/resources')
classifier = 'sources'
}
artifacts {
archives sourceJar
}
task generatePom(group: 'distribution', description: 'Generates POM file for uploading to repository') {
doLast {
def mavenPomDir = new File(project.buildDir, 'maven-pom')
mavenPomDir.mkdirs()
pom {
project {
name 'cuba-cli'
description 'CUBA Platform Development Command-Line Interface'
inceptionYear '2018'
licenses {
license {
name 'The Apache Software License, Version 2.0'
url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
}
}
organization {
name 'CUBA Platform'
url 'https://www.cuba-platform.com'
}
}
}.writeTo(new File(mavenPomDir, project.name + '-' + project.version + '.pom'))
}
}
assemble.dependsOn(generatePom)
mainClassName = "com.haulmont.cuba.cli.EntryPointKt"
startScripts {
doLast {
unixScript.text = unixScript.text
.replace(
"eval set -- \$DEFAULT_JVM_OPTS \$JAVA_OPTS \$CUBA_CLI_OPTS -classpath \"\\\"\$CLASSPATH\\\"\" $mainClassName \"\$APP_ARGS\"",
"eval set -- \$DEFAULT_JVM_OPTS \$JAVA_OPTS \$CUBA_CLI_OPTS -p \"\\\"\$CLASSPATH\\\"\" -m $moduleName/$mainClassName \"\$APP_ARGS\"")
windowsScript.text = windowsScript.text
.replace(
"\"%JAVA_EXE%\" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %CUBA_CLI_OPTS% -classpath \"%CLASSPATH%\" $mainClassName %CMD_LINE_ARGS%",
"\"%JAVA_EXE%\" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %CUBA_CLI_OPTS% -p \"%CLASSPATH%\" -m $moduleName/$mainClassName %CMD_LINE_ARGS%")
}
}
def bundlePlatform = project.hasProperty('targetOsPlatform') ? '-' + project.property('targetOsPlatform') : '';
def bundlesDir = file("bundles")
def modulesDir = file("${project.buildDir}/modules")
def bundleOutput = file("${buildDir}/bundle" + bundlePlatform)
def installedLibsDir = file("${buildDir}/install/cuba-cli/lib")
def patchLibsDir = file("${buildDir}/jar-patch")
def modulesConfig = [
'commons.lang' : "commons-lang-2.4-cuba.0.jar",
'commons.collections' : "commons-collections-3.2.2.jar",
'commons.configuration' : "commons-configuration-1.10.jar",
'commons.logging' : "commons-logging-1.1.1.jar",
'velocity' : "velocity-${velocityVersion}.jar",
'checker.qual' : "checker-qual-2.5.2.jar",
'error.prone.annotations' : "error_prone_annotations-2.1.3.jar",
'j2objc.annotations' : "j2objc-annotations-1.1.jar",
'animal.sniffer.annotations': "animal-sniffer-annotations-1.14.jar",
'com.google.common' : "guava-${guavaVersion}.jar",
'practicalxml' : "practicalxml-${practicalxmlVersion}.jar",
'jansi' : "jansi-${jansiVersion}.jar",
'jline' : "jline-${jlineVersion}.jar",
'jcommander' : "jcommander-${jCommanderVersion}.jar",
'kotlin.stdlib' : "kotlin-stdlib-${kotlin_version}.jar",
'kotlin.reflect' : "kotlin-reflect-${kotlin_version}.jar",
'kotlin.stdlib.jdk7' : "kotlin-stdlib-jdk7-${kotlin_version}.jar",
'kotlin.stdlib.jdk8' : "kotlin-stdlib-jdk8-${kotlin_version}.jar",
'kodein.di.core.jvm' : "kodein-di-core-jvm-${kodeinVersion}.jar",
'kodein.di.generic.jvm' : "kodein-di-generic-jvm-${kodeinVersion}.jar",
'gson' : "gson-${gsonVersion}.jar"
]
task jarPatch(dependsOn: installDist, group: 'build',
description: 'Patch dependencies with module information') {
inputs.dir bundlesDir
outputs.dir patchLibsDir
inputs.files installDist.outputs.files
doLast {
delete patchLibsDir
delete modulesDir
modulesDir.mkdirs()
// Compile module definitions
copy {
from installedLibsDir
into patchLibsDir
}
def javaHome = System.getenv('JAVA_HOME')
if (javaHome == null
|| javaHome.isEmpty()) {
throw new GradleException('JAVA_HOME is not set')
}
for (moduleItem in modulesConfig) {
def moduleItemName = moduleItem.key
def moduleItemJar = moduleItem.value
def jarFile = new File(patchLibsDir, moduleItemJar)
logger.info("Modularize ${moduleItemJar}")
logger.info("Compile module-info.class")
def compiledModuleDir = new File(modulesDir, moduleItemName)
exec {
workingDir modulesDir
commandLine(
"${javaHome}/bin/javac",
'-p', patchLibsDir.absolutePath,
'-d', compiledModuleDir.absolutePath,
'--patch-module', "${moduleItemName}=${jarFile.absolutePath}",
new File(project.file("bundles"), "${moduleItemName}/module-info.java").absolutePath
)
standardOutput = System.out
errorOutput = System.out
}
logger.info("Update JAR")
exec {
workingDir patchLibsDir
commandLine(
"${javaHome}/bin/jar",
'uf',
jarFile.absolutePath,
'-C',
compiledModuleDir.absolutePath,
'module-info.class'
)
standardOutput = System.out
errorOutput = System.out
}
}
}
}
task bundle(dependsOn: jarPatch, group: 'distribution', description: 'Builds bundle with custom JRE') {
outputs.dir bundleOutput
inputs.dir patchLibsDir
ext.appModulePaths = [patchLibsDir]
doLast {
delete bundleOutput
logger.info("Linking")
def javaHome = System.getenv('JAVA_HOME')
if (javaHome == null
|| javaHome.isEmpty()) {
throw new GradleException('JAVA_HOME is not set')
}
def targetOsJavaHome = project.hasProperty('targetOsJavaHome') ? project.property('targetOsJavaHome') : null
if (targetOsJavaHome == null
|| targetOsJavaHome.isEmpty()) {
targetOsJavaHome = javaHome
}
logger.info('Target JAVA_HOME ' + targetOsJavaHome)
// Call jlink
exec {
workingDir buildDir
commandLine(
"${javaHome}/bin/jlink",
'--module-path', (["${targetOsJavaHome}/jmods"] + ext.appModulePaths).grep().join(File.pathSeparator),
'--add-modules', moduleName,
'--output', bundleOutput,
'--launcher', "cuba-cli=$moduleName/$mainClassName",
'--compress=2',
'--no-header-files',
'--no-man-pages'
)
standardOutput = System.out
errorOutput = System.out
logger.info commandLine.join(' ')
}
logger.info("Remove standard launcher script")
def cubacliFile = new File(bundleOutput, "bin/cuba-cli")
def cubacliBatFile = new File(bundleOutput, "bin/cuba-cli.bat")
if (cubacliFile.exists()) {
cubacliFile.delete()
}
if (cubacliBatFile.exists()) {
cubacliBatFile.delete()
}
logger.info("Fix permissions")
// fix non-writable files in 'legal/'
def osName = System.getProperty("os.name").toLowerCase()
if (osName.contains('nux')
|| osName.contains('mac')) {
exec {
executable 'chmod'
args = ['u+w', '-R', bundleOutput]
}
}
def targetOsPlatform = 'linux'
if (osName.contains('mac')) {
targetOsPlatform = 'macos'
} else if (osName.contains('Win')) {
targetOsPlatform = 'windows'
}
if (project.hasProperty('targetOsPlatform')) {
targetOsPlatform = project['targetOsPlatform']
}
// create nested folder
def nativeBundle = new File(bundleOutput, 'native-' + targetOsPlatform)
nativeBundle.mkdir()
bundleOutput.eachFile { file ->
if (file.name != nativeBundle.name) {
file.renameTo(new File(nativeBundle, file.name))
}
}
// create custom launcher script
def binFolder = new File(bundleOutput, 'bin')
binFolder.mkdir()
if (targetOsPlatform == 'linux' || targetOsPlatform == 'macos') {
def cubaCliScript = new File(binFolder, 'cuba-cli')
cubaCliScript.text = project.file('etc/cuba-cli-unix').text
} else if (targetOsPlatform == 'windows') {
def cubaCliScript = new File(binFolder, 'cuba-cli.bat')
cubaCliScript.text = project.file('etc/cuba-cli-windows.bat').text
}
// set executable flag
if (osName.contains('nux')
|| osName.contains('mac')) {
exec {
executable 'chmod'
args = ['a+x', '-R', binFolder]
}
}
}
}
task buildWinSetup(dependsOn: bundle, group: 'distribution', description: 'Builds Windows installer') {
doLast {
if (project.hasProperty('targetOsPlatform') && project['targetOsPlatform'] == 'windows') {
def setupScriptDir = "${rootProject.projectDir}"
def setupScriptFile = "${setupScriptDir}/win-setup.iss"
def cliBuildBundleDir = "${project.buildDir}/bundle-windows"
def cliBuildDistributionsDir = "${project.buildDir}/distributions"
exec {
commandLine "cmd", "/c", "iscc",
"${setupScriptFile}",
"/DAppVersion=${version}",
"/DAppSrc=${cliBuildBundleDir}",
"/O${cliBuildDistributionsDir}"
}
} else {
throw new GradleException('Only for Windows targetOsPlatform')
}
}
}