forked from kermitt2/datastet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.gradle
More file actions
418 lines (350 loc) · 13 KB
/
build.gradle
File metadata and controls
418 lines (350 loc) · 13 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
buildscript {
repositories {
mavenLocal()
mavenCentral()
maven { url = "https://plugins.gradle.org/m2/" }
flatDir {
dirs 'localLibs'
}
}
dependencies {
classpath 'gradle.plugin.org.kt3k.gradle.plugin:coveralls-gradle-plugin:2.12.2'
classpath 'com.adarshr:gradle-test-logger-plugin:4.0.0'
classpath group: 'org.yaml', name: 'snakeyaml', version: '2.2'
}
}
plugins {
id 'com.gradleup.shadow' version '8.3.10'
id 'distribution'
id 'application'
}
apply plugin: 'jacoco'
jacoco {
toolVersion = '0.8.14'
}
apply plugin: 'java-library'
apply plugin: 'base'
apply plugin: 'com.github.kt3k.coveralls'
def getGitRevision() {
def gitRevision = "unknown"
try {
def result = providers.exec {
workingDir = rootProject.rootDir
commandLine 'git', 'describe', '--tags', '--always', '--first-parent'
}
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}"
}
}
group = "org.grobid.datastet"
version = '0.9.0'
description = """datastet"""
import javax.inject.Inject
import org.apache.tools.ant.taskdefs.condition.Os
import org.gradle.process.ExecOperations
java {
toolchain {
languageVersion = JavaLanguageVersion.of(21)
}
}
tasks.withType(JavaCompile).configureEach {
options.encoding = 'UTF-8'
}
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}"
}
repositories {
mavenLocal()
mavenCentral()
maven {
url = new File(rootProject.rootDir, "localLibs").toURI()
}
}
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 = []
}
dependencies {
implementation group: 'net.arnx', name: 'jsonic', version: '1.3.10'
//Logging
implementation 'org.slf4j:slf4j-api:1.7.36'
//Apache commons
implementation group: 'commons-pool', name: 'commons-pool', version: '1.6'
implementation group: 'commons-io', name: 'commons-io', version: '2.21.0'
implementation group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.5.14'
implementation group: 'org.apache.httpcomponents', name: 'httpmime', version: '4.5.14'
implementation group: 'org.apache.commons', name: 'commons-lang3', version: '3.20.0'
implementation group: 'org.apache.commons', name: 'commons-collections4', version: '4.5.0'
implementation group: 'org.apache.commons', name: 'commons-csv', version: '1.14.1'
//Dropwizard
implementation 'ru.vyarus:dropwizard-guicey:7.3.1'
implementation 'io.dropwizard:dropwizard-bom:4.0.17'
implementation 'io.dropwizard:dropwizard-core:4.0.17'
implementation 'io.dropwizard:dropwizard-assets:4.0.17'
implementation 'io.dropwizard:dropwizard-testing:4.0.17'
implementation 'io.dropwizard:dropwizard-forms:4.0.17'
implementation 'io.dropwizard:dropwizard-client:4.0.17'
implementation 'io.dropwizard:dropwizard-auth:4.0.17'
implementation 'io.dropwizard.metrics:metrics-core:4.2.38'
implementation 'io.dropwizard.metrics:metrics-servlets:4.2.38'
implementation group: 'com.google.guava', name: 'guava', version: '33.5.0-jre'
//Parsing xml/json
implementation group: 'com.fasterxml.jackson.core', name: 'jackson-core', version: '2.21.1'
implementation group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.21.1'
// jackson-annotations is pulled in transitively by jackson-databind
implementation group: 'xom', name: 'xom', version: '1.3.9'
implementation group: 'javax.xml.bind', name: 'jaxb-api', version: '2.3.0'
implementation group: 'com.sun.xml.bind', name: 'jaxb-core', version: '2.3.0'
implementation group: 'com.sun.xml.bind', name: 'jaxb-impl', version: '2.3.0'
implementation group: 'javax.activation', name: 'activation', version: '1.1.1'
implementation 'black.ninia:jep:4.3.1'
// for sentence segmentation only
implementation 'org.apache.opennlp:opennlp-tools:1.9.4'
implementation "joda-time:joda-time:2.14.0"
implementation "org.apache.lucene:lucene-analyzers-common:4.5.1"
implementation group: 'org.jruby', name: 'jruby-complete', version: '9.4.12.1'
implementation "org.apache.pdfbox:pdfbox:2.0.35"
implementation group: 'org.semanticweb.yars', name: 'nxparser-parsers', version: '2.3.3'
//Grobid
implementation(group: 'org.grobid', name: 'grobid-core', version: '0.9.0') {
exclude group: 'org.slf4j', module: "slf4j-log4j12"
}
api(group: 'org.grobid', name: 'grobid-service', version: '0.9.0') {
exclude group: 'org.slf4j', module: "slf4j-log4j12"
}
implementation(group: 'org.grobid', name: 'grobid-trainer', version: '0.9.0') {
exclude group: 'org.slf4j', module: "slf4j-log4j12"
}
//Tests
testImplementation(platform('org.junit:junit-bom:5.10.2'))
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")
testImplementation('org.junit.jupiter:junit-jupiter')
testRuntimeOnly("org.junit.vintage:junit-vintage-engine") {
because 'allows JUnit 3 and JUnit 4 tests to run'
}
testRuntimeOnly("org.junit.platform:junit-platform-launcher") {
because 'allows tests to run from IDEs that bundle older version of launcher'
}
testImplementation 'org.easymock:easymock:5.2.0'
testImplementation 'org.hamcrest:hamcrest-all:1.3'
testImplementation 'org.hamcrest:hamcrest-library:2.2'
testImplementation 'org.powermock:powermock-module-junit4:2.0.9'
testImplementation 'org.powermock:powermock-api-easymock:2.0.9'
}
configurations.all {
resolutionStrategy {
force 'xml-apis:xml-apis:1.4.01'
}
exclude group: 'org.slf4j', module: "slf4j-log4j12"
}
def getJavaLibraryPath = {
def jepLocalLibraries = ""
if (Os.isFamily(Os.FAMILY_MAC)) {
if (Os.OS_ARCH.equals("aarch64")) {
jepLocalLibraries = "${file("${grobidHome}/lib/mac_arm-64").absolutePath}"
} else {
jepLocalLibraries = "${file("${grobidHome}/lib/mac-64").absolutePath}"
}
} else if (Os.isFamily(Os.FAMILY_UNIX)) {
jepLocalLibraries = "${grobidHome}/lib/lin-64/jep:${grobidHome}/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
}
test {
testLogging.showStandardStreams = true
exclude '**/**IntegrationTest**'
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",
"--add-opens", "java.base/java.lang=ALL-UNNAMED",
"--add-opens", "java.base/java.util=ALL-UNNAMED"
}
systemProperty "java.library.path", "${System.getProperty('java.library.path')}:" + getJavaLibraryPath()
}
// 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;
}
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
apply plugin: 'java'
apply plugin: 'maven-publish'
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
}
}
repositories {
mavenLocal()
}
}
task install(dependsOn: publishToMavenLocal)
task mainJar(type: ShadowJar) {
zip64 = true
from sourceSets.main.output
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.DatastetMain'
}
from {
project.configurations.runtimeClasspath.collect {
it.isDirectory() ? [] : localLibs.contains(it.getName()) ? zipTree(it) : []
}
}
exclude("logback.xml")
configurations = [project.configurations.runtimeClasspath]
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}
jar {
dependsOn mainJar
enabled = true
}
distZip.enabled = true
distTar.enabled = false
shadowDistZip.enabled = false
shadowDistTar.enabled = false
artifacts {
archives jar
archives shadowJar
}
processResources {
filesMatching(["version.txt", "revision.txt"]) {
expand(
project_version: project.property('version') ?: "unknown",
project_revision: rootProject.ext.gitRevision
)
}
}
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 8+ 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/datastet")
def injected = objects.newInstance(InjectedExecOps)
doLast {
targetDir.parentFile.mkdirs()
if (targetDir.exists()) {
injected.execOps.exec {
workingDir = targetDir
commandLine 'git', 'pull'
}
} else {
injected.execOps.exec {
commandLine 'git', 'clone',
'https://huggingface.co/sciencialab/datastet-models',
targetDir.absolutePath
}
}
}
}
task installModels(dependsOn: [copyModels, downloadModelsGit]){
doLast {
def sourceDir = file("${grobidHome}/models/datastet")
def destDir = file("${grobidHome}/models/")
Arrays.asList(
"context_bert",
"context_creation_bert",
"context_shared_bert",
"context_used_bert",
"datasets-BERT_CRF",
"dataseer-binary_bert",
"dataseer-first_bert",
"dataseer-reuse_bert"
).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"
}
//////////
// service
apply plugin: 'application'
application {
mainClass = 'org.grobid.service.DatastetApplication'
run {
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", "${System.getProperty('java.library.path')}:" + getJavaLibraryPath()
args = ['server', 'resources/config/config.yml']
}
}
jacocoTestReport {
reports {
xml.required = true // coveralls plugin depends on xml format report
html.required = true
}
dependsOn test // tests are required to run before generating the report
}
coveralls {
jacocoReportPath = 'build/reports/jacoco/test/jacocoTestReport.xml'
}