forked from MegaMek/megameklab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle
463 lines (413 loc) · 15.1 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
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
plugins {
id 'application'
id 'maven-publish'
id 'edu.sc.seis.launch4j' version '2.4.4'
id 'org.ajoberstar.grgit' version '2.3.0'
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
group = 'org.megamek'
version = '0.47.1-SNAPSHOT'
sourceSets {
main {
java {
srcDirs = ['src']
}
resources {
srcDirs = ['resources']
}
}
}
ext {
mmlGitRoot = 'https://github.com/MegaMek/megameklab.git'
mmGitRoot = 'https://github.com/MegaMek/megamek.git'
// Work on MML or MHQ sometimes requires changes in MM as well. The maven publishing tasks use
// these properties to append the branch name to the artifact id if the repo is not in the master
// branch, making it available separately to the child project.
mmlBranch = grgit.branch.current.name
mmlBranchTag = mmlBranch.equals('master')? '' : '-' + mmlBranch
// Allows setting a dependency on a different MM branch.
mmBranch = 'master'
mmBranchTag = mmBranch.equals('master')? '' : '-' + mmBranch
mmDir = '../megamek'
}
// A settings_local.gradle file can be used to override any of the above options. For instance,
// rootProject.ext.mmlGitRoot = 'file:///path/to/local/repo' will cause the release target to clone a
// local copy of the repository rather than downloading it.
def localProperties = file('properties_local.gradle')
if (localProperties.exists()) {
apply from: localProperties
}
repositories {
mavenLocal()
maven {
url 'https://github.com/MegaMek/mavenrepo/raw/master'
}
jcenter()
}
configurations {
jarbundler
}
dependencies {
implementation "org.megamek:megamek${mmBranchTag}:${version}"
implementation 'log4j:log4j:1.2.17'
implementation 'org.apache.xmlgraphics:batik-dom:1.10'
implementation 'org.apache.xmlgraphics:batik-codec:1.10'
implementation 'org.apache.xmlgraphics:batik-rasterizer:1.10'
implementation ('org.apache.xmlgraphics:batik-bridge:1.10') {
// We don't need the python and javascript engine taking up space
exclude group: 'org.python', module: 'jython'
exclude group: 'org.mozilla', module: 'rhino'
}
implementation 'org.apache.xmlgraphics:batik-svggen:1.10'
// We have been using a modified version of svgSalamander, which we'll keep around until
// the conversion to batik is complete.
implementation files('lib/svgSalamander.jar')
jarbundler 'com.ultramixer.jarbundler:jarbundler-core:3.3.0'
}
mainClassName = 'megameklab.com.MegaMekLab'
ext {
jvmOptions = ['-Xmx1024m']
data = "data"
conf = "mmconf"
logDir = "logs"
docs = "docs"
lib = "lib"
unitFiles = "data/mechfiles"
distributionDir = "${buildDir}/distributions"
fileStagingDir = "${buildDir}/files"
repoDir = "${buildDir}/repo/megameklab"
mmRepoDir = "${buildDir}/repo/megamek"
mavenPublishDir = "${buildDir}/mavenrepo"
scriptsDir = "${projectDir}/scripts"
scriptTemplate = "${scriptsDir}/startScriptTemplate.txt"
osxApplicationStub = "${scriptsDir}/universalJavaApplicationStub"
osxBundleDir = "${buildDir}/osxBundle"
}
task setMMDir {
doLast{
if (hasProperty('localMMDir')) {
mmDir = findProperty('localMMDir')
} else {
println """To set the location of the MegaMek repository use the command line parameter
-Porg.gradle.project.mmDir=/path/to/local/mm/repo.git or set it in the settings_local.gradle
file. Defaulting to ${mmDir}"""
}
}
}
task compileMM (type: GradleBuild) {
description = 'Compiles the MM directory for packaging in a Jar'
buildFile = "${mmDir}/build.gradle"
dir = "${mmDir}"
tasks = [ 'compileTestJava' ]
}
task mmJar (type: Jar, dependsOn: compileMM) {
archiveName = "MegaMek.jar"
from "${mmDir}/megamek/build/classes/java/main"
from "${mmDir}/megamek/build/resources/main"
manifest {
attributes "Main-Class": mainClassName
attributes 'Class-Path' : (project.sourceSets.main.runtimeClasspath.files
.findAll { it.name.endsWith(".jar") }.collect { "${lib}/${it.name}" }.join(' '))
}
inputs.dir "${mmDir}/build/classes/java/main"
inputs.dir "${mmDir}/build/resources/main"
outputs.file "${buildDir}/libs/${archiveName}"
}
jar {
archiveName = "${rootProject.name}.${extension}"
manifest {
attributes "Main-Class": mainClassName
attributes 'Class-Path' : "${lib}/${mmJar.archiveName} " + (project.sourceSets.main.runtimeClasspath.files
.findAll { it.name.endsWith(".jar") }.collect { "${lib}/${it.name}" }.join(' '))
}
}
task copyFiles(type: Copy) {
description = 'Stages files that are to be copied into the distribution.'
from projectDir
include "${data}/**"
include "${conf}/**"
include "${docs}/**"
include 'license.txt'
exclude "**/*.psd"
into fileStagingDir
inputs.dir "${data}"
inputs.dir "${conf}"
inputs.dir "${docs}"
inputs.file 'license.txt'
outputs.dir fileStagingDir
}
task unitFilesZip (dependsOn: setMMDir) {
description = 'Creates zip archives of all the unit file folders from the MegaMek repository.'
file("${mmDir}/megamek/${unitFiles}").eachDir {subDir ->
dependsOn tasks.create("${name}${subDir.name}", Zip) {
from subDir
archiveName "${subDir.name}.zip"
destinationDir file("${fileStagingDir}/${unitFiles}")
}
}
inputs.dir "${mmDir}/${unitFiles}"
outputs.dir "${fileStagingDir}/${unitFiles}"
}
task stageFiles {
description = 'Process data files to be included in distribution'
group = 'distribution'
dependsOn copyFiles
dependsOn unitFilesZip
doLast {
mkdir "${fileStagingDir}/${logDir}"
ant.touch(file: "${fileStagingDir}/${logDir}/timestamp")
}
}
task createStartScripts (type: CreateStartScripts) {
description = 'Create shell script for generic distribution.'
applicationName = 'lab'
mainClassName = project.mainClassName
outputDir = startScripts.outputDir
classpath = jar.outputs.files + files(project.sourceSets.main.runtimeClasspath.files)
.filter { it.name.endsWith(".jar") }
defaultJvmOpts = project.ext.jvmOptions
// The default template assumes the start script is in a subdirectory and always
// sets APP_HOME to the parent directory of the one containing the script.
// So we provide a modified template.
unixStartScriptGenerator.template = resources.text.fromFile(scriptTemplate)
doLast {
// The start script assumes all the files on the classpath will be in the lib directory.
unixScript.text = unixScript.text.replace('lib/MegaMekLab', 'MegaMekLab')
windowsScript.text = windowsScript.text.replace('lib\\MegaMekLab', 'MegaMekLab')
// The Windows script just has a single line that needs to be changed to put the script in the root,
// so we'll do a simple replace
windowsScript.text = windowsScript.text.replace('set APP_HOME=%DIRNAME%..', '')
}
}
task createOSXBundle (dependsOn: jar) {
ext.appName = 'MegaMekLab'
// The jar directory is hard coded into jarbundler and has no public accessor
ext.jarSubdir = "${appName}.app/Contents/Resources/Java"
doLast {
mkdir osxBundleDir
ant.taskdef(name: 'jarbundler',
classname: 'com.ultramixer.jarbundler.JarBundler',
classpath: configurations.jarbundler.asPath)
ant.jarbundler (
name: ext.appName,
shortName: 'MegaMekLab',
build: rootProject.version,
version: rootProject.version.replace('-SNAPSHOT', ''),
bundleid: 'org.megamek.MegaMekLab',
mainClass: project.mainClassName,
stubfile: osxApplicationStub,
dir: osxBundleDir,
jar: "${jar.destinationDir}/${jar.archiveName}",
jvmversion: '1.8+',
icon: "${projectDir}/${data}/images/misc/megameklab.icns",
useJavaXKey: 'true',
workingdirectory: '$APP_PACKAGE/../',
extraclasspath: files(project.sourceSets.main.runtimeClasspath.files)
.filter { it.name.endsWith(".jar") }.collect { '$JAVAROOT/lib/' + it.name}.join(","),
vmoptions: '-Xmx1024m') {
javaproperty (name: 'apple.awt.brushMetal', value: 'true')
javaproperty (name: 'apple.laf.useScreenMenuBar', value: 'true')
}
}
}
distributions {
// Creates tasks which package distribution with MM jar and startup script in root directory
unix {
baseName = rootProject.name.toLowerCase()
contents {
from (fileStagingDir) {
exclude '**/history.txt'
}
from(createStartScripts.outputs.files) {
include "lab*"
}
from(jar)
from(mmJar) {
into "${lib}"
}
from (project.sourceSets.main.runtimeClasspath.files
.findAll { it.name.endsWith(".jar") && !it.name.toLowerCase().startsWith("megamek") }) {
into "${lib}"
}
duplicatesStrategy = 'exclude'
}
}
// Creates tasks which package distribution with MM jar wrapped in Windows executable
windows {
baseName = 'megameklab-windows'
contents {
from ("${buildDir}/launch4j") {
include '*.exe'
include '*.ini'
}
from fileStagingDir
from (project.sourceSets.main.runtimeClasspath.files
.findAll { it.name.endsWith(".jar") && !it.name.toLowerCase().startsWith("megamek") }) {
into "${lib}"
}
from (mmJar) {
into "${lib}"
}
duplicatesStrategy = 'exclude'
}
}
mac {
baseName = 'megameklab-mac'
contents {
from osxBundleDir
from fileStagingDir
from (mmJar) {
into "${createOSXBundle.jarSubdir}/${lib}"
}
from (project.sourceSets.main.runtimeClasspath.files
.findAll { it.name.endsWith(".jar") && !it.name.toLowerCase().startsWith("megamek") }) {
into "${createOSXBundle.jarSubdir}/${lib}"
}
duplicatesStrategy = 'exclude'
}
}
}
createExe {
description = 'Create Windows executable that wraps MM jar'
mainClassName = project.mainClassName
icon = "${projectDir}/data/images/misc/megameklab.ico"
def inifile = outfile.replace('.exe', '.l4j.ini')
inputs.file jar
outputs.file "${buildDir}/launch4j/${outfile}"
outputs.file "${buildDir}/launch4j/${inifile}"
doLast {
new File("${buildDir}/${outputDir}/${inifile}").text = """# Launch4j runtime config
# you can add arguments here that will be processed by the JVM at runtime
${project.ext.jvmOptions.join('\n')}
"""
}
}
windowsDistZip {
description = 'Creates Windows distribution packaged as a zip archive'
dependsOn createExe
}
unixDistTar {
description = 'Creates *nix distribution packaged as a tar ball'
dependsOn stageFiles
dependsOn startScripts
extension = 'tar.gz'
compression = Compression.GZIP
}
macDistTar {
description = 'Creates mac OSX distribution'
dependsOn stageFiles
dependsOn createOSXBundle
extension = 'tar.bz2'
compression = Compression.BZIP2
}
// The repository can only be cloned into an empty directory so we need to delete anything left over
// from a previous build
task deleteRepoDir (type: Delete) {
delete = "${repoDir}"
}
task deleteMMRepoDir (type: Delete) {
delete = "${mmRepoDir}"
}
task cloneRepo (type: Exec, dependsOn: deleteRepoDir) {
description = 'Clones the repository to ensure we are working with a clean directory tree'
group = 'distribution'
commandLine "git"
args "clone", "--branch", mmlBranch, "--single-branch", mmlGitRoot, "${repoDir}"
}
task cloneMMRepo (type: Exec, dependsOn: deleteMMRepoDir) {
description = 'Clones the MegaMek repository to ensure we are working with a clean directory tree'
group = 'distribution'
commandLine "git"
args "clone", "--branch", mmBranch, "--single-branch", mmGitRoot, "${mmRepoDir}"
}
task sourceZip (type: Zip) {
description 'Creates a zip archive of the source'
group = 'distribution'
from (rootDir) {
exclude "**/build/**"
exclude "**/.*"
}
archiveName "${rootProject.name.toLowerCase()}-${version}-source.zip"
destinationDir file(distributionDir)
}
task sourceTar (type: Tar) {
description 'Creates a compressed tar archive of the source'
from (rootDir) {
exclude "**/build/**"
exclude "**/.*"
}
archiveName "${rootProject.name.toLowerCase()}-${version}-source.tar.gz"
compression = Compression.GZIP
destinationDir file(distributionDir)
}
// The distribution plugin adds the distro packages to the assemble task, which causes the build task
// to run all the packaging tasks.
task assemble(overwrite: true) {
dependsOn jar
}
// Replace the assembleDist task created by the distributions plugin to create the packages we want to
task assembleDist(overwrite: true) {
description = 'Build unix, Windows, and source packages'
group = 'distribution'
dependsOn unixDistTar
dependsOn windowsDistZip
dependsOn macDistTar
}
task buildFromRepo (type: GradleBuild) {
description = 'Assembles the distribution packages in the clean repository copy'
group = 'distribution'
dependsOn cloneRepo
dependsOn cloneMMRepo
buildFile = "${repoDir}/build.gradle"
dir = "${repoDir}"
tasks = [ 'assembleDist' ]
}
task release (type: Copy) {
description = 'Builds the release packages from the repository and copies them into the project build directory'
group = 'distribution'
dependsOn buildFromRepo
from "${repoDir}/build/distributions"
into "${distributionDir}"
}
task sourcesJar(type: Jar) {
description = 'Creates a source archive for publication to a maven repository'
from sourceSets.main.allJava
classifier = 'sources'
}
task javadocJar(type: Jar) {
description = 'Creates a documentation archive for publication to a maven repository'
from javadoc
classifier = 'javadoc'
}
publishing {
publications {
publishMMLibrary(MavenPublication) {
artifactId = "megameklab${mmBranchTag}"
from components.java
artifact sourcesJar
// Javadoc has errors
// artifact javadocJar
pom {
name = "MegaMekLab"
description = "MegaMekLab"
url = "http://megamek.org"
licenses {
license {
name = "GNU General Public License, version 2"
url = "https://www.gnu.org/licenses/gpl-2.0.html"
}
}
}
}
}
repositories {
maven {
url uri(mavenPublishDir)
}
}
}
task cleanPublishingDir (type: Delete) {
delete = mavenPublishDir
}
publishPublishMMLibraryPublicationToMavenRepository.dependsOn cleanPublishingDir