forked from kolmafia/kolmafia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle
391 lines (344 loc) · 9.39 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
//-*- mode: groovy -*-
buildscript {
repositories {
mavenCentral()
}
}
plugins {
id 'application'
id 'jacoco'
id 'java'
id 'com.diffplug.spotless' version '6.23.3'
id 'com.gradleup.shadow' version '8.3.0'
id 'net.nemerosa.versioning' version '3.1.0'
id 'org.ajoberstar.grgit' version '5.2.2'
id 'org.panteleyev.jpackageplugin' version '1.6.0'
id "com.github.ben-manes.versions" version "0.51.0" // enables ./gradlew dependencyUpdates for outdated
}
sourceSets {
main {
java {
srcDirs = ['src', 'lib']
destinationDirectory.set(file('build/main'))
}
resources {
srcDirs = ['src', 'lib']
excludes = ['**/*.java', '**/*.jar']
}
}
lib {
java {
srcDirs = ['lib']
destinationDirectory.set(file('build/lib'))
}
}
test {
java {
srcDirs = ['test']
destinationDirectory.set(file('build/test'))
}
resources {
srcDirs = ['test/resources']
}
}
}
repositories {
// Use Maven Central for resolving dependencies.
mavenCentral()
}
dependencies {
// Use JUnit Jupiter for running JUnit5 tests.
testRuntimeOnly 'org.junit.platform:junit-platform-launcher:1.11.0'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter:5.11.0'
testImplementation 'org.hamcrest:hamcrest:3.0'
testImplementation 'com.spotify:hamcrest-optional:1.3.2'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.11.0'
testImplementation 'org.junit.jupiter:junit-jupiter-params:5.11.0'
testImplementation 'org.mockito:mockito-core:5.13.0'
testImplementation('org.eclipse.xtext:org.eclipse.xtext.xbase.lib:2.36.0') {
because 'assertion errors including Location/Range/Position need it'
}
testImplementation 'org.junit-pioneer:junit-pioneer:2.2.0'
implementation 'com.formdev:flatlaf:1.6.5'
implementation 'com.formdev:flatlaf-intellij-themes:1.6.5'
implementation 'com.formdev:flatlaf-swingx:1.6.5'
// Optional runtime deps for svnkit
runtimeOnly 'com.trilead:trilead-ssh2:1.0.0-build222'
runtimeOnly 'net.java.dev.jna:jna:5.14.0'
runtimeOnly 'net.java.dev.jna:jna-platform:5.14.0'
libImplementation 'org.swinglabs:swingx:1.0'
implementation files('build/lib') {
builtBy 'compileLibJava'
}
implementation 'net.sourceforge.htmlcleaner:htmlcleaner:2.29'
implementation('org.eclipse.lsp4j:org.eclipse.lsp4j:0.23.1') {
exclude group: 'org.eclipse.xtend', module: 'org.eclipse.xtend.lib'
}
implementation 'org.slf4j:slf4j-nop:2.0.16'
implementation 'org.fusesource.jansi:jansi:2.4.1'
implementation 'com.alibaba.fastjson2:fastjson2:2.0.53'
implementation 'org.mozilla:rhino:1.7.15'
implementation 'org.swinglabs:swingx:1.0'
implementation 'org.tmatesoft.svnkit:svnkit:1.10.11'
implementation 'com.jgoodies:jgoodies-binding:2.13.0'
implementation 'org.eclipse.jgit:org.eclipse.jgit:6.10.0.202406032230-r'
implementation 'org.eclipse.jgit:org.eclipse.jgit.ssh.apache:6.10.0.202406032230-r'
}
application {
// Define the main class for the application.
mainClass = 'net.sourceforge.kolmafia.KoLmafia'
}
spotless {
format 'misc', {
target '.gitignore'
trimTrailingWhitespace()
indentWithSpaces(2)
endWithNewline()
}
freshmark {
target '*.md'
}
groovyGradle {
greclipse()
}
java {
target 'src/**/*.java', 'test/**/*.java'
googleJavaFormat()
}
}
task cleanDist(type: Delete) {
onlyIf {
file('dist').exists()
}
inputs.dir('dist')
outputs.upToDateWhen { true }
doLast {
file('dist').eachFile(groovy.io.FileType.FILES) { File file ->
if (file.name.startsWith('KoLmafia-') && file.name.endsWith('.jar')) {
delete file
}
}
}
}
task pruneDist(type: Delete) {
onlyIf {
file('dist').exists()
}
inputs.dir('dist')
outputs.upToDateWhen { true }
doLast {
file('dist').eachFile(groovy.io.FileType.FILES) { File file ->
if (file.name.startsWith('KoLmafia-') && file.name.endsWith('.jar')) {
if (!file.name.contains(project.getVersion().toString()) || (isDirty() != file.name.endsWith('-M.jar'))) {
delete file
}
}
}
}
}
test {
useJUnitPlatform()
systemProperty 'line.separator', '\n'
systemProperty 'junit.jupiter.extensions.autodetection.enabled', true
systemProperty 'useCWDasROOT', true
systemProperty 'file.encoding', 'UTF-8'
workingDir 'test/root'
testLogging.showStandardStreams = true
reports {
html.required = true
junitXml.required = true
}
}
jacocoTestReport {
reports {
xml.required = true
}
}
jar {
manifest {
attributes(
'Main-Class' : 'net.sourceforge.kolmafia.KoLmafia',
'Build-Revision' : new Object() {
String toString() {
project.getVersion()
}
},
'Build-Branch' : versioning.info.branchId,
'Build-Build' : versioning.info.build,
'Build-Dirty' : isDirty(),
'Build-Jdk' : "${System.properties['java.version']} (${System.properties['java.vendor']} ${System.properties['java.vm.version']})",
'Build-OS' : "${System.properties['os.name']} ${System.properties['os.arch']} ${System.properties['os.version']}"
)
}
from {
configurations.runtimeClasspath.collect {
it.isDirectory() ? it : zipTree(it)
}
} {
exclude 'META-INF/*.RSA', 'META-INF/*.SF', 'META-INF/*.DSA'
}
duplicatesStrategy = 'exclude'
destinationDirectory = file('dist/')
archiveBaseName.set('KoLmafia')
archiveClassifier.set("${isDirty() ? 'M' : ''}")
}
shadowJar {
mustRunAfter cleanDist
duplicatesStrategy = 'exclude'
destinationDirectory = file('dist/')
archiveClassifier.set("${isDirty() ? 'M' : ''}")
}
task getRevision() {
onlyIf {
file('.git').exists()
}
def commit = findProperty('commit') ?: 'HEAD'
inputs.dir('.git')
inputs.property('commit', commit)
outputs.files file('build/revision.txt')
doLast {
def revision = grgit.log(includes:[commit]).size() - localCommits(commit)
logger.info('Commit: {} Revision: {}', commit, revision)
file('build/revision.txt').text = revision.toString().trim()
// Update the version to the new revision
project.setVersion(revision.toString().trim())
def revString = isDirty() ? project.getVersion() +'-M': project.getVersion()
println '\nRevision: ' + revString
}
}
task gitUpdate() {
doLast {
def remote = grgit.branch.current().trackingBranch.getName()
def latestHead = grgit.resolve.toCommit(remote)
grgit.fetch {
remote = remote
}
if (grgit.resolve.toCommit(remote) == latestHead) {
println 'Already up-to-date, nothing to do.'
return
}
def dirty = isDirty()
if (dirty) {
// This pollutes the reflog, but there's no stash functionality in
// grgit...
grgit.commit {
message = 'temporary stash commit'
all = true
}
}
grgit.pull {
rebase = true
}
if (dirty) {
grgit.reset {
mode = 'mixed'
commit = 'HEAD^'
}
}
}
}
java {
sourceCompatibility = JavaVersion.toVersion(javaSourceCompatibility)
targetCompatibility = JavaVersion.toVersion(javaTargetCompatibility)
}
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
tasks.withType(Test) {
// Mockito requires dynamic loading for mock creation.
jvmArgs("-XX:+EnableDynamicAgentLoading")
}
task cleanJpackage(type: Delete) {
onlyIf {
file('build/releases').exists()
}
delete 'build/releases'
}
gradle.taskGraph.whenReady { graph ->
if (graph.hasTask(":tsDefs") || graph.hasTask(":test")) {
compileJava.options.compilerArgs += "-parameters"
}
}
task tsDefs(type: JavaExec) {
classpath = sourceSets.main.runtimeClasspath
mainClass = "net.sourceforge.kolmafia.textui.TypescriptDefinition"
doFirst {
args lastRevision()
}
}
tsDefs.dependsOn getRevision
tasks.jpackage {
dependsOn shadowJar, cleanJpackage
input = 'dist'
destination = 'build/releases'
mainClass = 'net.sourceforge.kolmafia.KoLmafia'
appName = 'KoLmafia'
appVersion = new Date().format('yy.MM')
linux {
icon = 'util/linux/KoLmafia.ico'
}
mac {
type = 'dmg'
icon = 'util/macosx/limeglass.icns'
}
windows {
type = 'exe'
icon = 'util/windows/KoLmafia.ico'
winShortcut = true
winPerUserInstall = true
javaOptions = ["-DuseCWDasROOT=true"]
}
doFirst {
mainJar = tasks.shadowJar.archiveFileName.get()
appVersion += '.' + version + "${isDirty() ? 'M' : ''}"
println 'Packaging app ' + appName + '.' + appVersion + '...'
if (System.properties['os.name'] != 'Linux') {
return
}
def hasDeb = exec {
ignoreExitValue = true
errorOutput = OutputStream.nullOutputStream()
executable 'bash'
args '-c', 'which dpkg-deb'
}
def hasRpm = exec {
ignoreExitValue = true
errorOutput = OutputStream.nullOutputStream()
executable 'bash'
args '-c', 'which rpmbuild'
}
if (hasDeb.getExitValue() == 0) {
println 'Targeting deb for jpackage...'
linux { type = 'deb' }
} else if (hasRpm.getExitValue() == 0) {
println 'Targeting rpm for jpackage...'
linux { type = 'rpm' }
} else {
println 'Bundling all files for jpackage.'
linux { type = 'app-image' }
}
}
}
clean.dependsOn cleanDist
pruneDist.dependsOn getRevision
// Note that pruneDist relies on getRevision.
jar.dependsOn pruneDist
shadowJar.dependsOn pruneDist
startShadowScripts.dependsOn jar
startScripts.dependsOn jar
distTar.dependsOn shadowJar
distZip.dependsOn shadowJar
startScripts.dependsOn shadowJar
jacocoTestReport.dependsOn test
def isDirty() {
return versioning.info.dirty || localCommits(findProperty('commit') ?: 'HEAD') > 0
}
def localCommits(commit) {
return grgit.log(includes:[commit], excludes:['origin/main']).size()
}
def lastRevision() {
def revisionFile = file('build/revision.txt')
return revisionFile.exists() ? revisionFile.text.trim() : '0'
}
// Set version from last build/revision.txt if up-to-date
version = lastRevision()