-
Notifications
You must be signed in to change notification settings - Fork 232
/
build.gradle
346 lines (295 loc) · 12.4 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
apply plugin: 'application'
project.version = '5.3.1'
sourceCompatibility = '1.17'
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
ext.programName = 'Audiveris'
ext.programId = 'audiveris'
ext.programVersion = "$project.version"
ext.companyName = "$programName Ltd."
ext.companyId = "${programName}Ltd"
ext.jcppVersion = '1.5.9'
ext.leptVersion = '1.83.0'
ext.tessVersion = '5.3.1'
// this code is required in order to adapt values of os.name and os.arch to the
// conventions used by Javacpp's dependencies
ext.targetOSName = System.getProperty('os.name').toLowerCase()\
.startsWith('mac os x') ? 'macosx' :\
System.getProperty('os.name').split(' ')[0].toLowerCase()
ext.targetOSArch = ["i386":"x86", "i486":"x86", "i586":"x86", "i686":"x86", "x86":"x86",
"amd64":"x86_64", "x86-64":"x86_64", "x86_64":"x86_64", "arm":"armhf", "aarch64":"arm64"]\
[System.getProperty('os.arch').toLowerCase()]
ext.targetOS = "${project.ext.targetOSName}-${project.ext.targetOSArch}"
println "targetOS=${project.ext.targetOS}"
ext.makensisPath = null
if (!hasProperty('mainClass')) {
ext.mainClass = ext.programName
}
mainClassName = ext.mainClass
// Useful for turning on deprecation warnings
// Just uncomment the appropriate option
allprojects {
tasks.withType(JavaCompile) {
//options.compilerArgs << "-Xlint:deprecation"
options.compilerArgs << "-Xlint:unchecked"
}
}
// To circumvent limitations brought by Jigsaw
applicationDefaultJvmArgs = ["--add-exports=java.desktop/sun.awt.image=ALL-UNNAMED"]
run {
minHeapSize = '512m'
maxHeapSize = '1g'
// Retrieve CLI arguments from cmdLineArgs property if any
if (project.hasProperty("cmdLineArgs")) {
if (cmdLineArgs) {
args(cmdLineArgs.split(','))
}
}
// Retrieve JVM arguments from jvmLineArgs property if any
if (project.hasProperty("jvmLineArgs")) {
if (jvmLineArgs) {
jvmArgs(jvmLineArgs.split(','))
}
}
}
repositories {
maven {
name = 'JBoss repository' // required to obtain non-free JAI
url = 'https://repository.jboss.org/nexus/content/repositories/thirdparty-releases'
}
maven { // required for JAI Core 1.1.3
name = 'SpringSource Enterprise Bundle Repository - External Bundle Releases'
url = 'https://repository.springsource.com/maven/bundles/external'
}
mavenLocal()
mavenCentral()
//flatDir(dirs: 'dev/externals') // for libraries not in any other repository
}
sourceSets {
main {
java {
srcDir 'src/main'
srcDir "$buildDir/generated-src"
}
resources {
srcDir 'src/main' // Needed for BSAF use of properties
srcDir 'dev/icons'
}
}
test {
java {
srcDir 'src/test'
}
}
}
dependencies {
implementation(
[group: 'org.kohsuke', name: 'github-api', version: '1.301'],
[group: 'args4j', name: 'args4j', version: '2.33'],
[group: 'org.jdesktop.bsaf', name: 'bsaf', version: '1.9.2'],
[group: 'org.slf4j', name: 'slf4j-api', version: '1.7.35'],
[group: 'net.jcip', name: 'jcip-annotations', version: '1.0'],
[group: 'org.bushe', name: 'eventbus', version: '1.4'],
[group: 'ch.qos.logback', name: 'logback-classic', version: '1.2.10'],
[group: 'com.jgoodies', name: 'jgoodies-forms', version: '1.9.0'],
[group: 'com.jgoodies', name: 'jgoodies-looks', version: '2.7.0'],
[group: 'javax.media', name: 'jai-core', version: '1.1.3'],
[group: 'net.imagej', name: 'ij', version: '1.53j'],
[group: 'de.intarsys.opensource', name: 'jPodRenderer', version: '5.6'],
[group: 'org.audiveris', name: 'proxymusic', version: '4.0.2'],
[group: 'org.jgrapht', name: 'jgrapht-core', version: '1.5.1'],
[group: 'org.jfree', name: 'jfreechart', version: '1.5.3'],
[group: 'com.itextpdf', name: 'itextpdf', version: '5.5.13.2'],
[group: 'gov.nist.math', name: 'jama', version: '1.0.3'],
[group: 'org.reflections', name: 'reflections', version: '0.10.2'],
[group: 'org.bytedeco', name: 'javacpp', version: jcppVersion],
[group: 'org.bytedeco', name: 'leptonica', version: "${leptVersion}-${jcppVersion}"],
[group: 'org.bytedeco', name: 'tesseract', version: "${tessVersion}-${jcppVersion}"],
[group: 'com.github.jai-imageio', name: 'jai-imageio-core', version: '1.4.0'],
[group: 'org.apache.directory.studio', name: 'org.apache.commons.io', version: '2.4'],
[group: 'javax.xml.bind', name: 'jaxb-api', version: '2.3.1'],
[group: 'com.sun.xml.bind', name: 'jaxb-core', version: '2.3.0.1'],
[group: 'com.sun.xml.bind', name: 'jaxb-impl', version: '2.3.1']
)
runtimeOnly(
[group: 'org.bytedeco', name: 'leptonica', version: "${leptVersion}-${jcppVersion}", classifier: "${project.ext.targetOS}"],
[group: 'org.bytedeco', name: 'tesseract', version: "${tessVersion}-${jcppVersion}", classifier: "${project.ext.targetOS}"]
)
testImplementation(
[group: 'junit', name: 'junit', version: '4.13.2'],
[group: 'org.jgrapht', name: 'jgrapht-ext', version: '1.5.1']
)
}
// Needed since gradle replaced "compile" by "implementation"
// See https://stackoverflow.com/questions/47910578/not-able-to-copy-configurations-dependencies-after-upgrading-gradle-plugin-for-a
configurations {
implementationConfig.extendsFrom implementation
}
// Specific configurations for specific OS dependencies
['windows-x86', 'windows-x86_64'].each { os ->
configurations.create("runtime-$os")
dependencies.add("runtime-$os", [group: 'org.bytedeco', name: 'leptonica', version: "${leptVersion}-${jcppVersion}", classifier: "$os"])
dependencies.add("runtime-$os", [group: 'org.bytedeco', name: 'tesseract', version: "${tessVersion}-${jcppVersion}", classifier: "$os"])
}
jar {
// override default output archive name
archiveFileName = "audiveris.jar"
exclude ("**/doc-files/**")
destinationDirectory = file('build/jar')
// copy resources into the destination jar
from(file('res')) {
into 'res'
}
manifest {
attributes 'Built-By': project.ext.companyName
attributes 'Specification-Title': project.ext.programName
attributes 'Specification-Vendor': project.ext.companyName
attributes 'Specification-Version': project.version
attributes 'Implementation-Version': project.version
}
}
// Defining 'debug' task allows to set its arguments later
task(debug, dependsOn: 'classes', type: JavaExec) {
mainClass = mainClassName
classpath = sourceSets.main.runtimeClasspath
debug true
}
// retrieve the abbreviated hash for the latest commit from Git
task "git_build"(type:Exec) {
commandLine "git rev-parse --short HEAD".split(' ')
standardOutput = new ByteArrayOutputStream()
doLast {
project.ext.programBuild = standardOutput.toString().replaceAll('\n', '')
}
}
task generateProgramId(dependsOn: git_build) {
group "build"
description "Generates ProgramId source"
doLast{
project.ext.outputDir = file("$buildDir/generated-src/org/audiveris/omr")
def className = "ProgramId"
outputDir.exists() || outputDir.mkdirs()
def gSrc = new File(outputDir, "${className}.java")
gSrc.write("package org.audiveris.omr;\n\n")
gSrc.append("/**\n * Class {@code $className} provides full program identification.\n")
gSrc.append(" * This code has been automatically generated by Gradle.\n */\n")
gSrc.append("public abstract class $className {")
["company_name", "company_id", "program_name", "program_id", "program_version",\
"program_build"].each { str ->
def strParts = str.split("_")
def propName = strParts[0] + strParts[1].capitalize()
gSrc.append("\n /** Precise ${strParts[0]} ${strParts[1]}: {@value} */")
gSrc.append("\n public static final String ${str.toUpperCase()} = \"${project.ext."$propName"}\";\n")
}
gSrc.append("}\n")
}
}
compileJava.dependsOn("generateProgramId")
// Make sure we have an NSIS compiler available and store it into project.ext.makensisPath
task findNsisCompiler {
description "Find path to NSIS compiler"
onlyIf {"windows" == "${project.ext.targetOSName}"}
doLast {
// First test on PATH, then on standard program files locations
["", "C:/Program Files (x86)/NSIS/", "C:/Program Files/NSIS/"].each { prefix ->
if (project.ext.makensisPath == null) {
try {
def path = "${prefix}makensis.exe"
def proc = [path, "/VERSION"].execute()
proc.waitFor()
println "NSIS compiler $path found, version " + proc.in.text.trim()
project.ext.makensisPath = path
} catch (ignored) {
}
}
}
if (project.ext.makensisPath == null) {
throw new RuntimeException("Cannot find NSIS compiler (makensis.exe)!")
}
}
}
// All installers
task installers {
group "Installers"
description "Builds all installers"
}
// Windows installers for 32-bit and 64-bit
['windows-x86', 'windows-x86_64'].each { os ->
task "installer_$os"(type: Exec, dependsOn: [findNsisCompiler, jar, startScripts]) {
group "Installers"
description "Builds installer for $os"
onlyIf {"windows" == "${project.ext.targetOSName}"}
// Filter line that starts with "CLASSPATH=" or "set CLASSPATH=" findClasspath,
// and update os-based classifier information.
def updateClassPath = { findClasspath, line ->
line.startsWith("${findClasspath}=") ? line.replaceAll("-${project.ext.targetOS}.jar", "-${os}.jar") : line
}
doFirst {
mkdir "$buildDir/installers"
// Fresh population of os-dependent folder with bin+lib items
delete "$buildDir/installers/$os"
// bin: Scripts and icon
copy {
into "$buildDir/installers/$os/bin"
from("$buildDir/scripts/Audiveris") {filter updateClassPath.curry('CLASSPATH') }
from("$buildDir/scripts/Audiveris.bat") {filter updateClassPath.curry('set CLASSPATH')}
from "$projectDir/res/icon-256.ico"
}
// lib: Libraries
copy {
into "$buildDir/installers/$os/lib"
from "$buildDir/jar" // audiveris.jar
from configurations.implementationConfig // Compile jars
from configurations."runtime-$os" // OS-specific jars
}
// Set NSIS compiler command line
def suffix = (os == "windows-x86_64")? "" : "32"
commandLine "cmd", "/c",\
"${project.ext.makensisPath}",\
"/DPRODUCT_VERSION=$project.version",\
"/DPROJECT_DIR=$projectDir",\
"/DTARGET_OS=$os",\
"/DSUFFIX=$suffix",\
"$projectDir/dev/installer-windows/Installer.nsi"
}
}
installers.dependsOn("installer_$os")
}
javadoc {
title = "${project.ext.programName}-${project.version} API"
options.overview('src/main/overview.html')
// Copy images from src to javadoc hierarchy
doLast {
copy {
from 'src/main'
include '**/*.png'
into "$buildDir/docs/javadoc"
}
}
}
// To avoid too many warnings in building javadoc
if (JavaVersion.current().isJava8Compatible()) {
allprojects {
tasks.withType(Javadoc) {
options.addStringOption('Xdoclint:none', '-quiet')
}
}
}
// Ability to include private tasks (such as save)
fileTree("$projectDir/private").include('*.gradle').each { file ->
apply from: file
}
// Tell gradle to log standard output and error streams when running tests
test {
testLogging.showStandardStreams = true
}
// Utility task to print out head templates
task(printTemplates, dependsOn: 'classes', type: JavaExec) {
description = "Print out head templates with various sizes"
mainClass = "org.audiveris.omr.image.TemplateFactory"
classpath = sourceSets.main.runtimeClasspath
if (project.hasProperty("cmdLineArgs")) {
if (cmdLineArgs) {
args(cmdLineArgs.split())
}
}
}