Repository navigation
Expand file tree
/
Copy pathbuild.gradle
More file actions
888 lines (772 loc) · 35.6 KB
/
Copy pathbuild.gradle
File metadata and controls
888 lines (772 loc) · 35.6 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
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
buildscript {
// The shadow plugin (8.3.x and 9.x alike) declares log4j-core at runtime scope but only touches
// it in Log4j2PluginsCacheFileTransformer, which none of the shadowJar tasks here register via
// transform(). GROBID itself logs through slf4j/logback. Strip log4j from shadow's dependencies
// rather than chase its advisories with version pins. The rule is scoped to shadow on purpose:
// a blanket classpath exclude would also silently drop log4j from any future plugin that needs it.
// plexus-utils stays: shadow's transformers (including the ServiceFileTransformer behind
// mergeServiceFiles()) and relocation selectors use it, and shadow declares 4.0.2, below the
// CVE-2025-67030 fix (4.0.3).
dependencies {
components {
withModule('com.gradleup.shadow:shadow-gradle-plugin') {
allVariants {
withDependencies { deps ->
deps.removeAll { it.group == 'org.apache.logging.log4j' }
}
}
}
}
constraints {
classpath('org.codehaus.plexus:plexus-utils:4.1.0') {
because 'CVE-2025-67030: directory traversal in extractFile, fixed in plexus-utils 4.0.3'
}
}
}
}
plugins {
id 'org.jetbrains.kotlin.jvm' version '2.4.10' apply false
id 'com.gradleup.shadow' version '8.3.10' apply false
id 'com.adarshr.test-logger' version '4.0.0' apply false
id 'net.researchgate.release' version '3.1.0' apply false
id 'com.diffplug.spotless' version '8.2.1' apply false
}
repositories {
mavenLocal()
mavenCentral()
maven {
url = uri("https://plugins.gradle.org/m2/")
}
}
def getJavaLibraryPath = {
def jepLocalLibraries = ""
if (Os.isFamily(Os.FAMILY_MAC)) {
if (Os.OS_ARCH.equals("aarch64")) {
jepLocalLibraries = "${file("./grobid-home/lib/mac_arm-64").absolutePath}"
} else {
jepLocalLibraries = "${file("./grobid-home/lib/mac-64").absolutePath}"
}
} else if (Os.isFamily(Os.FAMILY_UNIX)) {
jepLocalLibraries = "${rootProject.rootDir.getAbsolutePath()}/grobid-home/lib/lin-64/jep:" +
"${rootProject.rootDir.getAbsolutePath()}/grobid-home/lib/lin-64"
} else {
throw new RuntimeException("Unsupported platform!")
}
def javaLibraryPath = "${System.getProperty('java.library.path')}:${jepLocalLibraries}"
def envPrefix = ""
if (System.env.CONDA_PREFIX) {
envPrefix = "${System.env.CONDA_PREFIX}"
} else if (System.env.VIRTUAL_ENV) {
envPrefix = "${System.env.VIRTUAL_ENV}"
}
if (envPrefix) {
def envLibs = "${envPrefix}/lib"
def pythonDirectory = file(envLibs).listFiles({ it.toString().contains("/lib/python") } as FileFilter)?.first()
def pythonVersion = (pythonDirectory =~ /python([0-9]\.[0-9]+)/)[0][1]
javaLibraryPath += ":${envLibs}:${envLibs}/python${pythonVersion}/site-packages/jep"
}
return javaLibraryPath
}
apply plugin: 'jacoco'
jacoco {
toolVersion = '0.8.14'
}
def getGitRevision() {
def gitRevision = "unknown"
try {
def stdout = new ByteArrayOutputStream()
println("Checking git under ${rootProject.rootDir}")
def proc = ['git', 'describe', '--tags', '--always'].execute(null, rootProject.rootDir)
proc.waitFor()
gitRevision = proc.in.text.trim()
println "Current Git revision: ${gitRevision}"
} catch (Exception e) {
println "Could not get Git revision: ${e}"
}
return gitRevision
}
project.ext.gitRevision = getGitRevision()
// Create a task to expose the revision for other tasks
tasks.register('collectGitRevision') {
doLast {
project.ext.gitRevision = getGitRevision()
println "Git revision: ${project.ext.gitRevision}"
}
}
allprojects {
apply plugin: 'net.researchgate.release'
group = "org.grobid"
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
// note: the following is not working
options.compilerArgs << '-parameters'
}
}
subprojects {
apply plugin: 'java'
apply plugin: 'maven-publish'
apply plugin: 'org.jetbrains.kotlin.jvm'
apply plugin: 'com.adarshr.test-logger'
apply plugin: 'com.diffplug.spotless'
spotless {
java {
target 'src/**/*.java'
// Exclude files carrying inherited third-party license headers (ASF and
// Google diff-match-patch) so their required attribution is preserved.
targetExclude(
'src/main/java/org/grobid/core/analyzers/ArabicChars.java',
'src/main/java/org/grobid/core/analyzers/GrobidDefaultAnalyzer.java',
'src/main/java/org/grobid/core/analyzers/GrobidFilterDeleteSpaceBetweenSameAlphabet.java',
'src/main/java/org/grobid/core/utilities/matching/DiffMatchPatch.java'
)
eclipse().configFile(rootProject.file('eclipse-formatter.xml'))
removeUnusedImports()
importOrder('java', 'javax', '', 'org.grobid')
licenseHeaderFile(rootProject.file('config/license-header.txt'))
trimTrailingWhitespace()
endWithNewline()
}
kotlin {
target 'src/**/*.kt'
ktlint().editorConfigOverride([
'ktlint_standard_no-wildcard-imports': 'disabled',
'max_line_length': 'off'
])
licenseHeaderFile(rootProject.file('config/license-header.txt'))
trimTrailingWhitespace()
endWithNewline()
}
}
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
//artifact jar
pom {
licenses {
license {
name = 'The Apache License, Version 2.0'
url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
}
}
}
}
}
repositories {
mavenLocal()
}
}
java {
toolchain {
languageVersion = JavaLanguageVersion.of(21)
}
}
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach {
kotlinOptions {
jvmTarget = "21"
}
}
repositories {
mavenCentral()
maven {
url = new File(rootProject.rootDir, "grobid-core/localLibs")
}
maven {
url = "https://jitpack.io"
}
}
configurations {
all*.exclude group: 'org.slf4j', module: "slf4j-log4j12"
all*.exclude group: 'log4j', module: "log4j"
// Mockito as an explicit Java agent (JDK 21+ disallows self-attaching agents by default)
mockitoAgent
}
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' task in grobid-core)
localLibs = ['crfpp-1.0.2.jar',
'langdetect-1.1-20120112.jar',
'grobid-lucene-analysers-0.0.2.jar',
'imageio-pnm-1.0.jar',
'wapiti-1.5.0.jar',
'blingfire-java-0.2.1.jar']
}
dependencies {
// packaging local libs inside grobid-core.jar
implementation fileTree(dir: new File(rootProject.rootDir, 'grobid-core/localLibs'), include: localLibs)
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine"
testRuntimeOnly "org.junit.vintage:junit-vintage-engine"
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")
}
testImplementation('org.junit.jupiter:junit-jupiter')
// JUnit 4 API (run via the vintage engine above). Previously pulled in transitively by
// powermock-module-junit4; declared explicitly now that PowerMock is removed.
testImplementation 'junit:junit:4.13.2'
testImplementation 'org.easymock:easymock:5.6.0'
testImplementation "org.mockito:mockito-core:5.24.0"
mockitoAgent("org.mockito:mockito-core:5.24.0") { transitive = false }
testImplementation "org.xmlunit:xmlunit-matchers:2.14.0"
testImplementation "org.xmlunit:xmlunit-legacy:2.14.0"
testImplementation "org.hamcrest:hamcrest-all:1.3"
testImplementation 'org.jetbrains.kotlin:kotlin-test'
implementation "com.cybozu.labs:langdetect:1.1-20120112"
implementation "com.rockymadden.stringmetric:stringmetric-core_2.11:0.27.4"
implementation "commons-pool:commons-pool:1.6"
implementation "commons-io:commons-io:2.21.0"
implementation "org.apache.commons:commons-lang3:3.20.0"
implementation "org.apache.commons:commons-collections4:4.5.0"
implementation 'org.apache.commons:commons-text:1.15.0'
implementation "com.google.guava:guava:33.6.0-jre"
implementation "org.apache.httpcomponents:httpclient:4.5.14"
implementation "black.ninia:jep:4.3.2"
implementation 'com.github.pemistahl:lingua:1.2.2'
// lingua 1.2.2 (its latest release) depends on moshi 1.13.0, which brings okio 2.10.0
// (CVE-2023-3635, fixed in okio 3.4.0). moshi 1.15.2, same major line, moves to okio 3.7.0;
// moshi-kotlin is kept at the same version as moshi.
constraints {
implementation('com.squareup.moshi:moshi:1.15.2') {
because 'CVE-2023-3635: okio < 3.4.0 via moshi 1.13.0; moshi 1.15.2 brings okio 3.7.0'
}
implementation('com.squareup.moshi:moshi-kotlin:1.15.2') {
because 'keep moshi-kotlin aligned with moshi'
}
}
implementation "com.fasterxml.jackson.core:jackson-core:2.21.6"
implementation "com.fasterxml.jackson.core:jackson-databind:2.21.6"
implementation "com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.21.4"
}
tasks.register('sourceJar', Jar) {
description = 'A jar that contains source code'
archiveClassifier = 'sources'
from sourceSets.main.allSource
}
artifacts {
archives sourceJar
archives jar
}
tasks.withType(Test) {
useJUnitPlatform()
testLogging.showStandardStreams = true
// One JVM per test task, not one per test class.
//
// This was forkEvery = 1, which spawns a fresh JVM for every test class -- 109 of
// them, run strictly one at a time (maxParallelForks is 1, and
// org.gradle.workers.max=1 in gradle.properties would cap it regardless). Each
// start pays JVM boot, the 1g heap below, the Mockito -javaagent, and
// java.library.path native library loading.
//
// Measured locally with `test --rerun-tasks -PskipCoverage`, same machine:
// 9m20s at forkEvery = 1 against 4m07s here, running an identical 812 tests across
// 109 classes with no failures. The difference is almost entirely process startup.
//
// The tests do share a JVM now, so anything depending on per-class isolation --
// static state in GrobidProperties, or a native library loaded through
// LibraryLoader -- would surface here rather than being papered over.
forkEvery = 0
maxHeapSize = "1024m"
def javaLibraryPath = getJavaLibraryPath()
if (JavaVersion.current().compareTo(JavaVersion.VERSION_1_8) > 0) {
jvmArgs "--add-opens", "java.base/java.util.stream=ALL-UNNAMED",
"--add-opens", "java.base/java.io=ALL-UNNAMED",
"--add-opens", "java.xml/jdk.xml.internal=ALL-UNNAMED"
}
// Attach Mockito explicitly so its inline mock maker (used for mockStatic) does not
// rely on self-attaching, which JDK 21+ warns about and will eventually disallow.
jvmArgs "-javaagent:${configurations.mockitoAgent.asPath}"
systemProperty "java.library.path", "${javaLibraryPath}"
}
}
/** SUBPROJECTS **/
project("grobid-core") {
apply plugin: 'com.gradleup.shadow'
apply plugin: 'jacoco'
configurations {
shadedLib
}
dependencies {
implementation("xml-apis:xml-apis") {
// otherwise xml-apis 2.0.1 will come from XOM and will result in
// java.lang.ClassNotFoundException: org.w3c.dom.ElementTraversal
//TODO: sort out this problem better
version {
strictly '1.4.01'
}
}
// Logs — slf4j 2.0.x + logback 1.5.x must move together: OpenNLP 2.5.x (and Dropwizard 5) pull
// slf4j-api 2.0.x, whose ServiceLoader binding (SLF4JServiceProvider) only exists in logback 1.5.x.
// logback 1.2.x would leave slf4j with no provider (NOP logging) in batch/standalone mode.
implementation 'org.slf4j:slf4j-api:2.0.19'
implementation 'ch.qos.logback:logback-classic:1.5.38'
implementation "org.apache.pdfbox:pdfbox:2.0.36"
api "xerces:xercesImpl:2.12.2"
// jsonic has no direct GROBID usage, but the bundled langdetect localLib (the default
// language detector) needs it at runtime to parse its language profiles. Keep it as a
// runtime-only dependency rather than exposing it on grobid-core's compile API.
runtimeOnly "net.arnx:jsonic:1.3.10"
api "net.sf.saxon:Saxon-HE:9.6.0-9"
api "xom:xom:1.4.6"
api 'javax.xml.bind:jaxb-api:2.3.0'
implementation "joda-time:joda-time:2.15.0"
implementation "org.apache.lucene:lucene-analyzers-common:4.10.4"
implementation 'black.ninia:jep:4.3.2'
implementation 'org.apache.opennlp:opennlp-tools:2.5.11'
// NOTE: jruby-complete bundles a vulnerable BouncyCastle (CVE-2026-5598) under its gem stdlib,
// but GROBID only uses jruby for the optional, non-default Pragmatic sentence segmenter, which
// never invokes Ruby's openssl — so the BC code is never loaded and the CVE is not triggerable.
// No released jruby ships a fixed BouncyCastle yet (latest bundles 1.83; the fix needs 1.84), so
// we leave it as-is and wait for an upstream jruby release with BouncyCastle >= 1.84.
implementation "org.jruby:jruby-complete:9.4.12.1"
shadedLib "org.apache.lucene:lucene-analyzers-common:4.10.4"
}
jar {
from {
project.configurations.runtimeClasspath.collect {
it.isDirectory() ? [] : localLibs.contains(it.getName()) ? zipTree(it) : []
}
}
exclude("logback.xml")
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}
shadowJar {
archiveClassifier = 'onejar'
mergeServiceFiles()
zip64 = true
manifest {
attributes 'Main-Class': 'org.grobid.core.main.batch.GrobidMain'
}
from sourceSets.main.output
from {
project.configurations.runtimeClasspath.collect {
it.isDirectory() ? [] : localLibs.contains(it.getName()) ? zipTree(it) : []
}
}
configurations = [project.configurations.shadedLib, project.configurations.runtimeClasspath]
relocate 'org.apache.lucene', 'org.grobid.shaded.org.apache.lucene'
}
artifacts {
archives jar
archives shadowJar
}
processResources {
inputs.property("gitRevision", rootProject.ext.gitRevision)
filesMatching(["grobid-version.txt", "grobid-revision.txt"]) {
expand(
project_version: project.property('version') ?: "unknown",
project_revision: rootProject.ext.gitRevision
)
}
}
tasks.register(
"install",
{
dependsOn publishToMavenLocal
dependsOn 'shadowJar'
}
)
}
project("grobid-home") {
tasks.register('packageGrobidHome', Zip) {
zip64 = true
from('.') {
include("config/*")
include("language-detection/**")
include("sentence-segmentation/**")
include("lib/**")
include("pdfalto/**")
include("models/**")
include("lexicon/**")
include("schemas/**")
include("scripts/**")
exclude("models/**/*.old")
}
into("grobid-home")
}
artifacts {
archives packageGrobidHome
}
}
import org.apache.tools.ant.taskdefs.condition.Os
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
project(":grobid-service") {
apply plugin: 'application'
apply plugin: 'jacoco'
apply plugin: 'com.gradleup.shadow'
application {
mainClass = 'org.grobid.service.main.GrobidServiceApplication'
}
tasks.run {
def javaLibraryPath = getJavaLibraryPath()
if (JavaVersion.current().compareTo(JavaVersion.VERSION_1_8) > 0) {
jvmArgs "--add-opens", "java.base/java.lang=ALL-UNNAMED"
}
workingDir = rootProject.rootDir
systemProperty "java.library.path", "${javaLibraryPath}"
}
tasks.distZip.enabled = true
tasks.distTar.enabled = false
//tasks.distZip.zip64 = true
tasks.shadowDistZip.enabled = false
tasks.shadowDistTar.enabled = false
distZip { duplicatesStrategy = DuplicatesStrategy.EXCLUDE }
distTar { duplicatesStrategy = DuplicatesStrategy.EXCLUDE }
dependencies {
implementation project(':grobid-core')
implementation project(':grobid-trainer')
//Dropwizard 5.x (Jakarta EE 10 / Jetty 12). guicey 8.x is the Dropwizard-5-compatible line.
implementation 'ru.vyarus:dropwizard-guicey:8.0.2'
// Dropwizard 5.0.1 ships Jetty 12.1.5, but CVE-2026-2332 (HTTP request smuggling) is only fixed
// on the 12.1.x line at 12.1.7+. Import the Jetty BOMs at 12.1.9 so every Jetty artifact is
// forced past the vulnerable version (Gradle picks the higher of the two BOM-managed versions).
implementation platform('org.eclipse.jetty:jetty-bom:12.1.13')
implementation platform('org.eclipse.jetty.ee10:jetty-ee10-bom:12.1.13')
implementation 'io.dropwizard:dropwizard-bom:5.0.2'
implementation 'io.dropwizard:dropwizard-core:5.0.2'
implementation 'io.dropwizard:dropwizard-assets:5.0.2'
implementation 'io.dropwizard:dropwizard-testing:5.0.2'
implementation 'io.dropwizard.modules:dropwizard-testing-junit4:5.0.0'
implementation 'io.dropwizard:dropwizard-forms:5.0.2'
implementation 'io.dropwizard:dropwizard-client:5.0.2'
implementation 'io.dropwizard:dropwizard-auth:5.0.2'
implementation 'io.dropwizard.metrics:metrics-core:4.2.40'
implementation 'io.dropwizard.metrics:metrics-servlets:4.2.40'
implementation 'io.dropwizard:dropwizard-json-logging:5.0.2'
// dropwizard-client 5.0.2 brings httpclient5 5.6.1, which declares httpcore5-h2 5.4 (and httpcore5
// 5.4, raised to 5.4.2 by dropwizard). Both are affected by two memory-exhaustion DoS issues in
// core5 <= 5.4.2, fixed in 5.4.3: CVE-2026-54399 (HTTP/1.1 parser, excessive headers) and
// CVE-2026-54428 (HTTP/2 HPACK decoder, oversized header blocks). Hold both core5 artifacts at
// 5.4.3 until an upstream bump.
// httpclient5 5.6.1 (also via dropwizard-client) leaks pooled connections on a
// Content-Encoding decode error (CVE-2026-64607, fixed in 5.6.3); 5.6.4 is the current 5.6.x
// and itself declares httpcore5 5.4.3. The dropwizard-bom manages logback at 1.5.33, which
// still has CVE-2026-10532 (object injection through HardenedObjectInputStream, fixed in
// 1.5.34): align the service on the same 1.5.38 as grobid-core and grobid-trainer.
constraints {
implementation('org.apache.httpcomponents.core5:httpcore5:5.4.3') {
because 'CVE-2026-54399 and CVE-2026-54428: header-based DoS, fixed in httpcore5 5.4.3'
}
implementation('org.apache.httpcomponents.core5:httpcore5-h2:5.4.3') {
because 'CVE-2026-54399 and CVE-2026-54428: header-based DoS, fixed in httpcore5 5.4.3'
}
implementation('org.apache.httpcomponents.client5:httpclient5:5.6.4') {
because 'CVE-2026-64607: connection leak on decode error, fixed in httpclient5 5.6.3'
}
implementation('ch.qos.logback:logback-classic:1.5.38') {
because 'CVE-2026-10532 and CVE-2026-9828: fixed in logback 1.5.34 / 1.5.33'
}
implementation('ch.qos.logback:logback-core:1.5.38') {
because 'CVE-2026-10532 and CVE-2026-9828: fixed in logback 1.5.34 / 1.5.33'
}
}
implementation "org.apache.pdfbox:pdfbox:2.0.36"
implementation "io.prometheus:simpleclient_dropwizard:0.16.0"
implementation "io.prometheus:simpleclient_servlet_jakarta:0.16.0"
implementation "io.prometheus:simpleclient_hotspot:0.16.0"
// Push-based metrics export over OTLP (complements the pull-based Prometheus scrape
// endpoint): the Prometheus Java client's own OTLP exporter, fed through the simpleclient
// bridge so the exact series set of the scrape endpoint (application metrics + hotspot
// JVM/process exports) is pushed — no second instrumentation with the OpenTelemetry SDK.
implementation "io.prometheus:prometheus-metrics-exporter-opentelemetry:1.8.0"
implementation "io.prometheus:prometheus-metrics-simpleclient-bridge:1.8.0"
}
shadowJar {
archiveClassifier = 'onejar'
mergeServiceFiles()
zip64 = true
manifest {
attributes 'Main-Class': 'org.grobid.core.main.batch.GrobidMain'
}
exclude("logback.xml")
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}
artifacts {
archives shadowJar
}
distributions {
main {
contents {
//from(new File(rootProject.rootDir, "grobid-service/README.md")) {
// into "doc"
//}
from(new File(rootProject.rootDir, "../grobid-home/config/grobid.yaml")) {
into "config"
}
from(new File(rootProject.rootDir, "grobid-service/build/scripts/*")) {
into "bin"
}
}
}
}
}
project(":grobid-trainer") {
apply plugin: 'com.gradleup.shadow'
apply plugin: 'jacoco'
dependencies {
implementation("xml-apis:xml-apis") {
// otherwise xml-apis 2.0.1 will come from XOM and will result in
// java.lang.ClassNotFoundException: org.w3c.dom.ElementTraversal
//TODO: sort out this problem better
version {
strictly '1.4.01'
}
}
implementation project(':grobid-core')
// progressbar pulls in the org.jline:jline uber-jar, which bundles the vulnerable
// jline-remote-telnet server (GHSA-47qp-hqvx-6r3f, GHSA-2r2c-cx56-8933). GROBID never
// starts a telnet server and progressbar only uses the terminal API, so we exclude the
// uber-jar and depend solely on jline-terminal, removing the telnet module entirely.
implementation("me.tongfei:progressbar:0.9.5") {
exclude group: 'org.jline', module: 'jline'
}
implementation "org.jline:jline-terminal:3.30.16"
// logs — see grobid-core: slf4j 2.0.x needs logback 1.5.x for its ServiceLoader binding.
implementation 'org.slf4j:slf4j-api:2.0.19'
implementation 'ch.qos.logback:logback-classic:1.5.38'
}
configurations {
}
jar {
from {
project.configurations.runtimeClasspath.collect {
it.isDirectory() ? [] : localLibs.contains(it.getName()) ? zipTree(it) : []
}
}
exclude("logback.xml")
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}
shadowJar {
archiveClassifier = 'onejar'
mergeServiceFiles()
zip64 = true
manifest {
attributes 'Main-Class': 'org.grobid.trainer.TrainerRunner'
}
from('src/main/resources') {
include '*.xml'
}
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}
artifacts {
archives shadowJar
archives jar
}
task install {
dependsOn publishToMavenLocal
dependsOn 'shadowJar'
}
def trainerTasks = [
"train_name_header" : "org.grobid.trainer.NameHeaderTrainer",
"train_name_citation" : "org.grobid.trainer.NameCitationTrainer",
"train_affiliation_address" : "org.grobid.trainer.AffiliationAddressTrainer",
"train_shorttext" : "org.grobid.trainer.ShorttextTrainer",
"train_figure" : "org.grobid.trainer.FigureTrainer",
"train_table" : "org.grobid.trainer.TableTrainer",
"train_citation" : "org.grobid.trainer.CitationTrainer",
"train_date" : "org.grobid.trainer.DateTrainer",
"train_reference_segmentation" : "org.grobid.trainer.ReferenceSegmenterTrainer",
"train_patent_citation" : "org.grobid.trainer.PatentParserTrainer",
"train_funding_acknowledgement": "org.grobid.trainer.FundingAcknowledgementTrainer"
]
def complexTrainerTasks = [
"train_header" : ["org.grobid.trainer.HeaderTrainer", ""],
"train_header_article_light" : ["org.grobid.trainer.HeaderTrainer", "article/light"],
"train_header_article_light_ref" : ["org.grobid.trainer.HeaderTrainer", "article/light-ref"],
"train_header_ietf" : ["org.grobid.trainer.HeaderTrainer", "sdo/ietf"],
"train_segmentation" : ["org.grobid.trainer.SegmentationTrainer", ""],
"train_segmentation_article_light" : ["org.grobid.trainer.SegmentationTrainer", "article/light"],
"train_segmentation_article_light_ref": ["org.grobid.trainer.SegmentationTrainer", "article/light-ref"],
"train_segmentation_ietf" : ["org.grobid.trainer.SegmentationTrainer", "sdo/ietf"],
"train_fulltext" : ["org.grobid.trainer.FulltextTrainer", ""],
"train_fulltext_article_light" : ["org.grobid.trainer.FulltextTrainer", "article/light"],
"train_fulltext_article_light_ref" : ["org.grobid.trainer.FulltextTrainer", "article/light-ref"],
]
def libraries = ""
if (Os.isFamily(Os.FAMILY_MAC)) {
if (Os.OS_ARCH.equals("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)) {
if (Os.OS_ARCH.equals("aarch64")) {
libraries = "${file("../grobid-home/lib/lin_arm-64/jep").absolutePath}:" +
"${file("../grobid-home/lib/lin_arm-64").absolutePath}:"
} else {
libraries = "${file("../grobid-home/lib/lin-64/jep").absolutePath}:" +
"${file("../grobid-home/lib/lin-64").absolutePath}:"
}
} else {
throw new RuntimeException("Unsupported platform!")
}
trainerTasks.each { taskName, mainClassName ->
tasks.create(name: taskName, type: JavaExec, group: 'modeltraining') {
mainClass = mainClassName
classpath = sourceSets.main.runtimeClasspath
def javaLibraryPath = getJavaLibraryPath()
if (JavaVersion.current().compareTo(JavaVersion.VERSION_1_8) > 0) {
jvmArgs '-Xmx3072m', "--add-opens", "java.base/java.lang=ALL-UNNAMED"
} else {
jvmArgs '-Xmx3072m'
}
systemProperty "java.library.path", "${javaLibraryPath}"
}
}
complexTrainerTasks.each { taskName, mainClassNameAndArgs ->
tasks.create(name: taskName, type: JavaExec, group: 'modeltraining') {
mainClass = mainClassNameAndArgs[0]
classpath = sourceSets.main.runtimeClasspath
def javaLibraryPath = getJavaLibraryPath()
if (JavaVersion.current().compareTo(JavaVersion.VERSION_1_8) > 0) {
jvmArgs '-Xmx3072m', "--add-opens", "java.base/java.lang=ALL-UNNAMED"
} else {
jvmArgs '-Xmx3072m'
}
systemProperty "java.library.path", "${javaLibraryPath}"
args mainClassNameAndArgs[1]
}
}
// evaluation tasks
ext.getArg = { propName, defaultVal ->
return project.hasProperty(propName) ? project.getProperty(propName) : defaultVal;
}
// run like this:
// ./gradlew checkEvalConfig
// ./gradlew jatsEval -Pp2t=/path/to/goldenSet
// ./gradlew jatsEval -Pp2t=/path/to/goldenSet -Prun=1 -PfileRatio=0.1
// ./gradlew teiEval -Pp2t=/path/to/goldenSet
// ./gradlew PrepareDOIMatching -Pp2t=ABS_PATH_TO_PMC/PMC_sample_1943
// ./gradlew EvaluateDOIMatching -Pp2t=ABS_PATH_TO_PMC/PMC_sample_1943
// Pre-flight check of grobid.yaml before running the end-to-end evaluation:
// verifies biblio-glutton consolidation is enabled and reachable, and that the
// DeLFT-recommended models are set to engine: "delft". Fails (exit 1) if not.
// Pass -PcheckMode=warn to only report problems without failing (exit 0).
task(checkEvalConfig, dependsOn: 'classes', type: JavaExec, group: 'modelevaluation') {
mainClass = 'org.grobid.trainer.evaluation.EvaluationConfigCheck'
classpath = sourceSets.main.runtimeClasspath
if (getArg('checkMode', 'strict') == 'warn') {
args 'warn'
}
def javaLibraryPath = getJavaLibraryPath()
if (JavaVersion.current().compareTo(JavaVersion.VERSION_1_8) > 0) {
jvmArgs '-Xmx1024m', "--add-opens", "java.base/java.lang=ALL-UNNAMED"
} else {
jvmArgs '-Xmx1024m'
}
systemProperty "java.library.path", "${javaLibraryPath}"
}
task(jatsEval, dependsOn: 'classes', type: JavaExec, group: 'modelevaluation') {
mainClass = 'org.grobid.trainer.evaluation.EndToEndEvaluation'
classpath = sourceSets.main.runtimeClasspath
args 'nlm', getArg('p2t', '.'), getArg('run', '0'), getArg('fileRatio', '1.0'), getArg('flavor', '')
def javaLibraryPath = getJavaLibraryPath()
if (JavaVersion.current().compareTo(JavaVersion.VERSION_1_8) > 0) {
jvmArgs '-Xmx3072m', "--add-opens", "java.base/java.lang=ALL-UNNAMED"
} else {
jvmArgs '-Xmx3072m'
}
systemProperty "java.library.path", "${javaLibraryPath}"
systemProperty "grobid.progressbar", getArg('progressbar', 'auto')
}
task(teiEval, dependsOn: 'classes', type: JavaExec, group: 'modelevaluation') {
mainClass = 'org.grobid.trainer.evaluation.EndToEndEvaluation'
classpath = sourceSets.main.runtimeClasspath
args 'tei', getArg('p2t', '.'), getArg('run', '0'), getArg('fileRatio', '1.0'), getArg('flavor', '')
def javaLibraryPath = getJavaLibraryPath()
if (JavaVersion.current().compareTo(JavaVersion.VERSION_1_8) > 0) {
jvmArgs '-Xmx3072m', "--add-opens", "java.base/java.lang=ALL-UNNAMED"
} else {
jvmArgs '-Xmx3072m'
}
systemProperty "java.library.path", "${javaLibraryPath}"
systemProperty "grobid.progressbar", getArg('progressbar', 'auto')
}
task(PrepareDOIMatching, dependsOn: 'classes', type: JavaExec, group: 'modelevaluation') {
mainClass = 'org.grobid.trainer.evaluation.EvaluationDOIMatching'
classpath = sourceSets.main.runtimeClasspath
args 'data', getArg('p2t', '.')
def javaLibraryPath = getJavaLibraryPath()
if (JavaVersion.current().compareTo(JavaVersion.VERSION_1_8) > 0) {
jvmArgs '-Xmx3072m', "--add-opens", "java.base/java.lang=ALL-UNNAMED"
} else {
jvmArgs '-Xmx3072m'
}
systemProperty "java.library.path", "${javaLibraryPath}"
}
task(EvaluateDOIMatching, dependsOn: 'classes', type: JavaExec, group: 'modelevaluation') {
mainClass = 'org.grobid.trainer.evaluation.EvaluationDOIMatching'
classpath = sourceSets.main.runtimeClasspath
args 'eval', getArg('p2t', '.')
def javaLibraryPath = getJavaLibraryPath()
if (JavaVersion.current().compareTo(JavaVersion.VERSION_1_8) > 0) {
jvmArgs '-Xmx3072m', "--add-opens", "java.base/java.lang=ALL-UNNAMED"
} else {
jvmArgs '-Xmx3072m'
}
systemProperty "java.library.path", "${javaLibraryPath}"
}
}
/** JACOCO **/
// Coverage instrumentation is opt-out, for CI legs that do not publish it.
//
// The jacoco agent attaches to every forked test JVM and instruments classes as they load.
// Only one CI leg publishes it (to Coveralls); on the others that cost is paid and thrown away.
//
// configureEach (rather than a plain withType) so this resolves after the subprojects have
// applied the jacoco plugin, and findByType so projects without it are simply skipped.
if (providers.gradleProperty('skipCoverage').present) {
allprojects {
tasks.withType(Test).configureEach {
def jacocoExtension = it.extensions.findByType(JacocoTaskExtension)
if (jacocoExtension != null) {
jacocoExtension.enabled = false
}
}
}
}
tasks.register("codeCoverageReport", JacocoReport) {
// If a subproject applies the 'jacoco' plugin, add the result it to the report
subprojects { subproject ->
subproject.plugins.withType(JacocoPlugin).configureEach {
subproject.tasks.matching({ t -> t.extensions.findByType(JacocoTaskExtension) }).configureEach { testTask ->
sourceSets subproject.sourceSets.main
executionData(testTask)
}
// To automatically run `test` every time `./gradlew codeCoverageReport` is called,
// you may want to set up a task dependency between them as shown below.
// Note that this requires the `test` tasks to be resolved eagerly (see `forEach`) which
// may have a negative effect on the configuration time of your build.
subproject.tasks.matching({ t -> t.extensions.findByType(JacocoTaskExtension) }).forEach {
rootProject.tasks.codeCoverageReport.dependsOn(it)
}
}
}
// XML -> Coveralls (uploaded by the coverallsapp/github-action step in CI),
// HTML -> for manual check
reports {
xml.required = true
csv.required = true
html.outputLocation = layout.buildDirectory.dir("jacocoHtml")
html.required = true
}
}
wrapper {
gradleVersion = "9.0.0"
}
build.dependsOn project.getSubprojects().collect({ it.getTasks().getByName("build") })
release {
failOnUnversionedFiles = false
failOnCommitNeeded = false
tagTemplate = '${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.
// The string is treated as a regex by net.researchgate.release.
requireBranch.set('.*release.*')
}
}