forked from Audiveris/audiveris
-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.gradle
315 lines (270 loc) · 11.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
apply plugin: 'java'
apply plugin: 'application'
sourceCompatibility = '1.7'
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
ext.programName = 'Audiveris'
ext.programId = 'audiveris'
ext.programVersion = '5.1.1'
ext.companyName = "$programName Ltd."
ext.companyId = "${programName}Ltd"
// 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"]\
[System.getProperty('os.arch').toLowerCase()]
ext.targetOS = "${project.ext.targetOSName}-${project.ext.targetOSArch}"
println "targetOS=${project.ext.targetOS}"
ext.makensisPath = null
//ext.dl4jVersion = '0.8.0'
//ext.nd4jVersion = '0.8.0'
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"
}
}
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 {
jcenter()
maven {
name = 'JBoss repository' // required to obtain non-free JAI
url = 'https://repository.jboss.org/nexus/content/repositories/thirdparty-releases'
}
mavenLocal()
//flatDir(dirs: 'dev/externals') // for libraries not in any other repository
}
sourceSets {
main {
java {
srcDir 'src/main'
}
resources {
srcDir 'src/main'
srcDir 'dev/icons'
}
}
test {
java {
srcDir 'src/test'
}
}
}
// Declare Lombok appropriately to avoid deprecation warnings in Gradle >= 4.6
dependencies {
compileOnly 'org.projectlombok:lombok:1.16.20'
annotationProcessor 'org.projectlombok:lombok:1.16.20'
testAnnotationProcessor 'org.projectlombok:lombok:1.16.20'
}
dependencies {
compile(
[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.21'],
[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.1.7'],
[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.51f'],
[group: 'de.intarsys.opensource', name: 'jPodRenderer', version: '5.6'],
[group: 'org.audiveris', name: 'proxymusic', version: '3.0.1'],
[group: 'org.jgrapht', name: 'jgrapht-core', version: '1.0.1'],
[group: 'org.jfree', name: 'jfreechart', version: '1.0.19'],
[group: 'com.itextpdf', name: 'itextpdf', version: '5.5.9'],
[group: 'gov.nist.math', name: 'jama', version: '1.0.3'],
[group: 'org.reflections', name: 'reflections', version: '0.9.10'],
[group: 'org.bytedeco', name: 'javacpp', version: '1.3'],
[group: 'org.bytedeco.javacpp-presets', name: 'leptonica', version: '1.73-1.3'],
[group: 'org.bytedeco.javacpp-presets', name: 'tesseract', version: '3.04.01-1.3'],
[group: 'com.github.jai-imageio', name: 'jai-imageio-core', version: '1.3.1'],
// [group: 'org.deeplearning4j', name: 'deeplearning4j-core', version: "${project.ext.dl4jVersion}"],
// [group: 'org.nd4j', name: 'nd4j-native', version: "${project.ext.nd4jVersion}"],
[group: 'org.apache.directory.studio', name: 'org.apache.commons.io', version: '2.4']
)
runtime(
// [group: 'org.nd4j', name: 'nd4j-native', version: "${project.ext.nd4jVersion}", classifier: "${project.ext.targetOS}"],
[group: 'org.bytedeco.javacpp-presets', name: 'leptonica', version: '1.73-1.3', classifier: "${project.ext.targetOS}"],
[group: 'org.bytedeco.javacpp-presets', name: 'tesseract', version: '3.04.01-1.3', classifier: "${project.ext.targetOS}"]
)
testCompile(
[group: 'junit', name: 'junit', version: '4.10'],
[group: 'org.jgrapht', name: 'jgrapht-ext', version: '1.0.1']
)
}
// Specific configurations for specific OS dependencies
['windows-x86', 'windows-x86_64'].each { os ->
configurations.create("runtime-$os")
dependencies.add("runtime-$os", [group: 'org.bytedeco.javacpp-presets', name: 'leptonica', version: '1.73-1.3', classifier: "$os"])
dependencies.add("runtime-$os", [group: 'org.bytedeco.javacpp-presets', name: 'tesseract', version: '3.04.01-1.3', classifier: "$os"])
}
jar {
// override default output archive name
archiveName = "audiveris.jar"
exclude ("**/doc-files/**")
destinationDir = 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.ext.programVersion
attributes 'Implementation-Version': project.ext.programVersion
}
}
// Defining 'debug' task allows to set its arguments later
task(debug, dependsOn: 'classes', type: JavaExec) {
main = 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 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")
sourceSets {
main {
java {
srcDir { "$buildDir/generated-src/org/audiveris/omr" }
}
}
}
// 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.compile // 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=$programVersion",\
"/DPROJECT_DIR=$projectDir",\
"/DTARGET_OS=$os",\
"/DSUFFIX=$suffix",\
"$projectDir/dev/installer-windows/Installer.nsi"
}
}
installers.dependsOn("installer_$os")
}
javadoc {
doFirst {
copy {
from "src/main/java/org/audiveris/omr"
into "$buildDir/docs/javadoc/org/audiveris/omr"
include ("*/doc-files/**")
}
}
title = "${project.ext.programName}-${project.ext.programVersion} API"
options.overview('src/main/overview.html')
}
// Ability to include private tasks (such as save)
fileTree("$projectDir/private").include('*.gradle').each { file ->
apply from: file
}