-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathbuild.gradle
More file actions
521 lines (448 loc) · 18.3 KB
/
Copy pathbuild.gradle
File metadata and controls
521 lines (448 loc) · 18.3 KB
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
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
import javax.inject.Inject
import org.apache.tools.ant.taskdefs.condition.Os
import org.gradle.process.ExecOperations
buildscript {
repositories {
mavenLocal()
mavenCentral()
maven {
url "https://plugins.gradle.org/m2/"
}
maven {
name = 'ajoberstar-backup'
url = 'https://ajoberstar.org/bintray-backup/'
}
}
dependencies {
classpath group: 'org.yaml', name: 'snakeyaml', version: '1.19'
}
}
plugins {
id 'java'
id 'application'
id 'maven-publish'
id 'jacoco'
id 'com.gradleup.shadow' version '8.3.10'
id "de.undercouch.download" version "4.1.1"
id 'net.researchgate.release' version '3.1.0'
id "org.jetbrains.kotlin.jvm" version "2.2.20"
}
group = "org.grobid"
description = """The goal of this GROBID module is to recognize in textual documents any expressions of
measurements (e.g. pressure, temperature, etc.), to parse and normalization them, and finally to convert
these measurements into SI units. We focus our work on technical and scientific articles (text, XML and PDF input)
and patents (text and XML input)."""
// Deliberately *not* --first-parent: a release made on a branch and merged back with a merge
// commit leaves its tag on the second parent, so --first-parent walks straight past it and
// reports the previous release. After releasing v0.9.0 on a branch and merging, master would
// describe as v0.8.2-2-g<sha> instead of v0.9.0-4-g<sha>.
// --always keeps a bare commit sha as the fallback when no tag is reachable, e.g. in the
// shallow clones CI checks out.
def getGitRevision() {
def gitRevision = "unknown"
try {
def result = providers.exec {
workingDir = rootProject.rootDir
commandLine 'git', 'describe', '--tags', '--always'
}
gitRevision = result.standardOutput.asText.get().trim()
} catch (Exception e) {
println "Could not get Git revision: ${e}"
}
return gitRevision
}
project.ext.gitRevision = getGitRevision()
tasks.register('collectGitRevision') {
project.ext.gitRevision = getGitRevision()
doLast {
println "Git revision: ${project.ext.gitRevision}"
}
}
tasks.withType(JavaCompile).configureEach {
options.encoding = 'UTF-8'
// options.compilerArgs << "-Xlint:deprecation"
// options.compilerArgs << "-Xlint:unchecked"
}
kotlin {
jvmToolchain(21)
}
java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(21))
}
}
tasks.run.workingDir = rootProject.rootDir
ext {
// treating them separately, these jars will be flattened into grobid-core.jar on installing,
// to avoid missing dependencies from the projects that include grobid-core (see 'jar' taskin grobid-core)
localLibs = []
}
repositories {
mavenLocal()
mavenCentral()
maven { url 'https://jitpack.io' }
maven { url "https://oss.jfrog.org/artifactory/libs-snapshot" }
maven { url "https://oss.jfrog.org/artifactory/libs-release" }
flatDir {
dirs 'localLibs'
}
}
dependencies {
//Tests
testImplementation(platform('org.junit:junit-bom:5.14.1'))
testRuntimeOnly("org.junit.platform:junit-platform-launcher") {
because("Only needed to run tests in a version of IntelliJ IDEA that bundles older versions")
}
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine")
testRuntimeOnly("org.junit.vintage:junit-vintage-engine")
testImplementation('org.junit.jupiter:junit-jupiter')
testImplementation 'org.easymock:easymock:5.6.0'
testImplementation 'org.hamcrest:hamcrest-all:1.3'
testImplementation 'org.mockito:mockito-core:5.14.2'
// JUnit 4 API for compilation (was previously provided transitively by
// powermock-module-junit4); JUnit 4 tests are executed by junit-vintage-engine.
testImplementation 'junit:junit:4.13.2'
testImplementation 'org.jetbrains.kotlin:kotlin-test'
testImplementation "io.mockk:mockk:1.13.17"
//GROBID
implementation 'org.grobid:grobid-core:0.9.1'
implementation 'org.grobid:grobid-trainer:0.9.1'
implementation 'org.grobid:grobid-service:0.9.1'
implementation 'xerces:xercesImpl:2.12.2'
implementation "net.arnx:jsonic:1.3.10"
implementation "net.sf.saxon:Saxon-HE:9.6.0-9"
implementation "xom:xom:1.3.2"
implementation 'javax.xml.bind:jaxb-api:2.3.0'
// Must match the opennlp-tools version Grobid 0.9.1 is built against (2.5.9):
// grobid-core calls SentenceDetectorME.sentPosDetect(CharSequence), an OpenNLP 2.x
// overload. A lower direct pin here overrides the transitive 2.5.9 and causes a
// runtime NoSuchMethodError during sentence segmentation.
implementation 'org.apache.opennlp:opennlp-tools:2.5.9'
implementation 'black.ninia:jep:4.3.1'
implementation "org.apache.httpcomponents:httpclient:4.5.14"
implementation "org.apache.lucene:lucene-analyzers-common:4.5.1"
implementation group: 'org.jruby', name: 'jruby-complete', version: '9.2.13.0'
//Apache commons
implementation 'org.apache.commons:commons-collections4:4.5.0'
implementation 'org.apache.commons:commons-lang3:3.20.0'
implementation 'commons-logging:commons-logging:1.2'
implementation 'commons-io:commons-io:2.21.0'
implementation 'commons-pool:commons-pool:1.6'
implementation 'commons-codec:commons-codec:1.14'
//Json
implementation 'com.fasterxml.jackson.core:jackson-core:2.21.1'
implementation 'com.fasterxml.jackson.core:jackson-databind:2.21.1'
implementation 'com.fasterxml.jackson.module:jackson-module-afterburner:2.21.1'
implementation 'com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.21.1'
// measurements
// (1) UOM 2.x
implementation 'tech.units:indriya:2.1.3'
implementation group: 'si.uom', name: 'si-units', version: '2.1'
implementation group: 'si.uom', name: 'si-quantity', version: '2.1'
implementation group: 'systems.uom', name: 'systems-quantity', version: '2.1'
implementation group: 'systems.uom', name: 'systems-common', version: '2.1'
implementation group: 'systems.uom', name: 'systems-unicode', version: '2.1'
implementation group: 'systems.uom', name: 'systems-ucum', version: '2.1'
implementation group: 'systems.uom', name: 'systems-unicode', version: '2.1'
//Dropwizard 5.x (Jakarta EE 10 / Jetty 12) to match Grobid 0.9.1. guicey 8.x is the
// Dropwizard-5-compatible line. Jetty 12 removed the org.eclipse.jetty.servlets
// CrossOriginFilter/QoSFilter; the service now uses CrossOriginHandler/QoSHandler.
implementation 'ru.vyarus:dropwizard-guicey:8.0.2'
// Dropwizard 5.0.1 ships Jetty 12.1.5; force the Jetty BOMs to 12.1.9 (CVE-2026-2332).
implementation platform('org.eclipse.jetty:jetty-bom:12.1.9')
implementation platform('org.eclipse.jetty.ee10:jetty-ee10-bom:12.1.9')
implementation 'io.dropwizard:dropwizard-bom:5.0.1'
implementation 'io.dropwizard:dropwizard-core:5.0.1'
implementation 'io.dropwizard:dropwizard-assets:5.0.1'
implementation 'io.dropwizard:dropwizard-testing:5.0.1'
implementation 'io.dropwizard:dropwizard-forms:5.0.1'
implementation 'io.dropwizard:dropwizard-client:5.0.1'
implementation 'io.dropwizard:dropwizard-auth:5.0.1'
implementation 'io.dropwizard.metrics:metrics-core:4.2.38'
implementation 'io.dropwizard.metrics:metrics-servlets:4.2.38'
//Misc
implementation 'com.googlecode.clearnlp:clearnlp:1.3.1'
implementation 'com.google.guava:guava:33.5.0-jre'
implementation "net.arnx:jsonic:1.3.10"
// XML
implementation 'org.codehaus.woodstox:stax2-api:4.2.1'
implementation 'com.fasterxml.woodstox:woodstox-core:6.4.0'
// Needed for compatibility with JDK > 8
implementation 'javax.activation:activation:1.1.1'
}
configurations {
implementation.exclude group: "org.slf4j", module: "slf4j-jdk14"
implementation.exclude group: 'org.slf4j', module: "slf4j-log4j12"
implementation.exclude group: 'log4j', module: "log4j"
}
configurations.configureEach {
resolutionStrategy {
force 'xml-apis:xml-apis:1.4.01'
}
}
/** Other configuration **/
sourceSets.main.resources {
srcDirs = ["src/main/resources", "resources/config"]
}
sourceSets.test.resources {
srcDirs = ["src/test/resources"]
}
test {
exclude '**/**IntegrationTest**'
useJUnitPlatform()
maxHeapSize = "1024m"
def libraries = ""
if (Os.isFamily(Os.FAMILY_MAC)) {
if (Os.isArch("aarch64")) {
libraries = "${file("./grobid-home/lib/mac_arm-64").absolutePath}"
} else {
libraries = "${file("./grobid-home/lib/mac-64").absolutePath}"
}
} else if (Os.isFamily(Os.FAMILY_UNIX)) {
def jepDir = rootProject.rootDir.getAbsolutePath() + "/grobid-home/lib/lin-64/jep"
libraries = jepDir
jepDir = rootProject.rootDir.getAbsolutePath() + "/grobid-home/lib/lin-64"
libraries += ":" + jepDir
} else {
throw new RuntimeException("Unsupported platform!")
}
if (JavaVersion.current().compareTo(JavaVersion.VERSION_1_8) > 0) {
// Reflective access needed by the test mocking frameworks (EasyMock/Mockito) on Java 21
jvmArgs "--add-opens", "java.base/java.util.stream=ALL-UNNAMED",
"--add-opens", "java.base/java.io=ALL-UNNAMED",
"--add-opens", "java.base/java.lang=ALL-UNNAMED",
"--add-opens", "java.base/java.util=ALL-UNNAMED",
"--add-opens", "java.base/java.util.regex=ALL-UNNAMED",
"--add-opens", "java.base/java.math=ALL-UNNAMED",
"--add-opens", "java.base/java.text=ALL-UNNAMED",
"--add-opens", "java.xml/jdk.xml.internal=ALL-UNNAMED"
}
systemProperty "java.library.path", "${System.getProperty('java.library.path')}:" + libraries
}
tasks.run.workingDir = rootProject.rootDir
application {
mainClass = 'org.grobid.service.main.GrobidQuantitiesApplication'
}
run {
args = ['server', 'resources/config/config.yml']
def libraries = ""
if (Os.isFamily(Os.FAMILY_MAC)) {
if (Os.isArch("aarch64")) {
libraries = "${file("../grobid-home/lib/mac_arm-64").absolutePath}"
} else {
libraries = "${file("../grobid-home/lib/mac-64").absolutePath}"
}
} else if (Os.isFamily(Os.FAMILY_UNIX)) {
libraries = "${file("../grobid-home/lib/lin-64/jep").absolutePath}:" +
"${file("../grobid-home/lib/lin-64").absolutePath}:"
} else {
throw new RuntimeException("Unsupported platform!")
}
if (JavaVersion.current().compareTo(JavaVersion.VERSION_1_8) > 0) {
jvmArgs "--add-opens", "java.base/java.lang=ALL-UNNAMED"
}
workingDir = rootProject.rootDir
def javaLibraryPath = "${System.getProperty('java.library.path')}:" + libraries
systemProperty "java.library.path", javaLibraryPath
}
task integration(type: Test) {
include '**'
maxHeapSize = "1024m"
def libraries = ""
if (Os.isFamily(Os.FAMILY_MAC)) {
if (Os.isArch("aarch64")) {
libraries = "${file("./grobid-home/lib/mac_arm-64").absolutePath}"
} else {
libraries = "${file("./grobid-home/lib/mac-64").absolutePath}"
}
} else if (Os.isFamily(Os.FAMILY_UNIX)) {
def jepDir = rootProject.rootDir.getAbsolutePath() + "/grobid-home/lib/lin-64/jep"
libraries = jepDir
jepDir = rootProject.rootDir.getAbsolutePath() + "/grobid-home/lib/lin-64"
libraries += ":" + jepDir
} else {
throw new RuntimeException("Unsupported platform!")
}
if (JavaVersion.current().compareTo(JavaVersion.VERSION_1_8) > 0) {
// Reflective access needed by the test mocking frameworks (EasyMock/Mockito) on Java 21
jvmArgs "--add-opens", "java.base/java.util.stream=ALL-UNNAMED",
"--add-opens", "java.base/java.io=ALL-UNNAMED",
"--add-opens", "java.base/java.lang=ALL-UNNAMED",
"--add-opens", "java.base/java.util=ALL-UNNAMED",
"--add-opens", "java.base/java.util.regex=ALL-UNNAMED",
"--add-opens", "java.base/java.math=ALL-UNNAMED",
"--add-opens", "java.base/java.text=ALL-UNNAMED",
"--add-opens", "java.xml/jdk.xml.internal=ALL-UNNAMED"
}
systemProperty "java.library.path", "${System.getProperty('java.library.path')}:" + libraries
}
// Training configuration
def trainerTasks = [
//Training models
"train_units" : "org.grobid.trainer.UnitTrainer",
"train_quantities" : "org.grobid.trainer.QuantitiesTrainer",
"train_values" : "org.grobid.trainer.ValueTrainer",
"train_quantifiedObjects": "org.grobid.trainer.QuantifiedObjectTrainer"
]
trainerTasks.each { taskName, trainerMainClass ->
tasks.create(name: taskName, type: JavaExec, group: 'training') {
mainClass = trainerMainClass
classpath = sourceSets.main.runtimeClasspath
}
}
// return the default value if the property has not been specified in command line
ext.getArg = { propName, defaultVal ->
return project.hasProperty(propName) ? project.getProperty(propName) : defaultVal;
}
processResources {
// The version and the revision are injected here rather than read from the source files, so
// Gradle cannot see them change and keeps the task UP-TO-DATE: revision.txt would otherwise
// hold whatever value it was first generated with. Building the release tag in a tree that
// had already been built on master would then bake the master revision into the artifact.
// Declaring them as inputs makes the task re-run whenever either changes.
inputs.property('projectVersion', project.property('version').toString())
inputs.property('gitRevision', rootProject.ext.gitRevision)
filesMatching(["version.txt", "revision.txt"]) {
expand(
project_version: project.property('version') ?: "unknown",
project_revision: rootProject.ext.gitRevision
)
}
}
/*** Packaging and distribution ***/
shadowJar {
archiveClassifier = 'onejar'
mergeServiceFiles()
zip64 true
manifest {
attributes 'Main-Class': 'org.grobid.service.main.GrobidQuantitiesApplication'
}
from sourceSets.main.output
configurations = [project.configurations.runtimeClasspath]
}
jar {
enabled true
}
artifacts {
archives shadowJar
}
distZip.enabled = true
distTar.enabled = false
shadowDistZip.enabled = false
shadowDistTar.enabled = false
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
}
}
repositories {
mavenLocal()
}
}
def conf = new org.yaml.snakeyaml.Yaml().load(new File("resources/config/config.yml").newInputStream())
def grobidHome = conf.grobidHome.replace("\$", "").replace('{', "").replace("GROBID_HOME:- ", "").replace("}", "")
if (grobidHome.startsWith("../")) {
grobidHome = "${rootProject.rootDir}/${grobidHome}"
}
/** Model management **/
task copyModels(type: Copy) {
from "${rootDir}/resources/models"
include "**/*.wapiti"
include "**/config.json"
include "**/transformer-config.json"
include "**/transformer-tokenizer/**"
include "**/model_weights.hdf5"
include "**/preprocessor.json"
exclude "**/features-engineering/**"
exclude "**/result-logs/**"
into "${grobidHome}/models/"
doLast {
print "Copy models under grobid-home: ${grobidHome}"
}
}
// Gradle 9 removed the dynamic `exec {}` shortcut inside task actions, so we
// inject ExecOperations via a helper interface and call it from doLast.
interface InjectedExecOps {
@Inject ExecOperations getExecOps()
}
task downloadModelsGit(dependsOn: copyModels) {
def targetDir = file("${grobidHome}/models/quantities_models")
def injected = objects.newInstance(InjectedExecOps)
doLast {
targetDir.parentFile.mkdirs()
// Requires git-xet to be installed beforehand (https://hf.co/docs/hub/git-xet),
// since the HuggingFace repository stores large model files via Xet storage.
if (targetDir.exists()) {
injected.execOps.exec {
workingDir = targetDir
commandLine 'git', 'pull'
}
} else {
injected.execOps.exec {
commandLine 'git', 'clone',
'https://huggingface.co/sciencialab/grobid-quantities-models',
targetDir.absolutePath
}
}
}
}
task installModels(dependsOn: [copyModels, downloadModelsGit]) {
doLast {
def sourceDir = file("${grobidHome}/models/quantities_models")
def destDir = file("${grobidHome}/models/")
Arrays.asList(
"quantities",
"quantities-BERT_CRF",
"quantities-BidLSTM_CRF",
"quantities-BidLSTM_CRF_FEATURES",
"units-BERT_CRF",
"units-BidLSTM_CRF",
"units-BidLSTM_CRF_FEATURES",
"units",
"values-BERT_CRF",
"values-BidLSTM_CRF",
"values-BidLSTM_CRF_FEATURES",
"values",
).each { String subDirName ->
var subDir = new File(sourceDir, subDirName)
if (subDir.isDirectory()) {
copy {
from subDir
into new File(destDir, subDirName)
}
}
}
delete files("${sourceDir}")
}
}
wrapper {
gradleVersion = "9.0.0"
}
test {
useJUnitPlatform()
}
jacocoTestReport {
reports {
xml.required = true // consumed by coverallsapp/github-action in CI
html.required = true
}
dependsOn test // tests are required to run before generating the report
}
release {
failOnUnversionedFiles = false
failOnCommitNeeded = false
tagTemplate = 'v${version}'
git {
// Releases must be cut from a branch whose name contains "release"
// (e.g. `release/0.9.0`, `feature/release-0.9.0`, `prepare-release-0.9.0`).
// Direct release from `master` is intentionally blocked: master is
// protected and the gradle-release plugin cannot push there. Cut the
// release on a release-named branch, then bring it back to master via
// a PR merged with a merge commit (NOT squash) so the tagged commit
// remains reachable from master history - which is also what lets
// getGitRevision() above report the new release rather than the previous one.
// The string is treated as a regex by net.researchgate.release.
requireBranch.set('.*release.*')
}
}