blob: 8ff5c3bea8e88f85271365debfacd9def3ce01b0 [file] [log] [blame]
Marc Kupietz4f6ed422024-03-01 07:27:46 +01001plugins {
2 // Apply the org.jetbrains.kotlin.jvm Plugin to add support for Kotlin.
dependabot[bot]feae6fc2026-03-16 08:59:45 +00003 id 'org.jetbrains.kotlin.jvm' version '2.3.20'
Marc Kupietz4f6ed422024-03-01 07:27:46 +01004
5 // Apply the application plugin to add support for building a CLI application in Java.
6 id 'application'
Marc Kupietz1b595992024-03-01 14:54:30 +01007 id 'com.github.johnrengelman.shadow' version '8.1.1'
Marc Kupietz4f6ed422024-03-01 07:27:46 +01008}
9
Marc Kupietz4f6ed422024-03-01 07:27:46 +010010repositories {
Marc Kupietz4f6ed422024-03-01 07:27:46 +010011 mavenCentral()
Marc Kupietzf7deb222026-04-05 20:14:45 +020012 maven { url = 'https://jitpack.io' }
Marc Kupietz4f6ed422024-03-01 07:27:46 +010013}
14
Marc Kupietz47b43c32024-03-27 20:43:32 +010015test {
Marc Kupietzfc18d282025-08-31 12:07:46 +020016 minHeapSize = "512m"
17 maxHeapSize = "4096m"
18 jvmArgs '-XX:MaxMetaspaceSize=1024m'
Marc Kupietz2a3223d2025-11-19 21:05:21 +010019
20 // Enable parallel test execution for faster builds
21 maxParallelForks = Runtime.runtime.availableProcessors().intdiv(2) ?: 1
Marc Kupietzec7c2ae2025-12-04 10:09:45 +010022 systemProperty 'korapxmltool.test', 'true'
Marc Kupietz47b43c32024-03-27 20:43:32 +010023}
24
Marc Kupietz4f6ed422024-03-01 07:27:46 +010025dependencies {
26 // Align versions of all Kotlin components
27 implementation platform('org.jetbrains.kotlin:kotlin-bom')
28
29 // Use the Kotlin JDK 8 standard library.
30 implementation 'org.jetbrains.kotlin:kotlin-stdlib'
Marc Kupietzfc18d282025-08-31 12:07:46 +020031 implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.10.2'
Marc Kupietz4f6ed422024-03-01 07:27:46 +010032
33 // This dependency is used by the application.
Marc Kupietzde917592025-10-31 15:44:27 +010034 implementation 'com.google.guava:guava:33.5.0-jre'
Marc Kupietz4f6ed422024-03-01 07:27:46 +010035
Marc Kupietz31122362024-03-02 11:13:37 +010036
Marc Kupietzfc18d282025-08-31 12:07:46 +020037 implementation ("info.picocli:picocli:4.7.7")
Marc Kupietz31122362024-03-02 11:13:37 +010038
Marc Kupietz4f6ed422024-03-01 07:27:46 +010039 // Use the Kotlin test library.
40 testImplementation 'org.jetbrains.kotlin:kotlin-test'
41
42 // Use the Kotlin JUnit integration.
43 testImplementation 'org.jetbrains.kotlin:kotlin-test-junit'
dependabot[bot]feae6fc2026-03-16 08:59:45 +000044 testImplementation "org.jetbrains.kotlin:kotlin-test:2.3.20"
Marc Kupietz0c6e8772024-03-19 07:03:07 +010045
Marc Kupietz1465ce22024-03-26 09:51:17 +010046 implementation 'com.github.kupietz:cistern:v1.0.4'
Marc Kupietzaf682a42024-03-22 06:51:55 +010047 implementation 'org.maltparser:maltparser:1.9.2'
dependabot[bot]8ecd00c2025-12-15 08:36:52 +000048 implementation 'org.apache.opennlp:opennlp-tools:2.5.7'
Marc Kupietze481b6a2025-12-26 16:06:59 +010049 implementation('edu.stanford.nlp:stanford-corenlp') {
50 version {
51 strictly '[3.0.0, 4.0.0)'
52 prefer '3.9.2'
53 }
54 because 'CoreNLP 4.x changed model format incompatible with models currently used for DeReKo'
55 }
Marc Kupietzfc18d282025-08-31 12:07:46 +020056 implementation 'org.slf4j:slf4j-simple:2.0.17'
Marc Kupietz916bdfe2024-09-20 09:02:57 +020057 implementation 'org.apache.ant:ant:1.10.15'
Marc Kupietzfc18d282025-08-31 12:07:46 +020058 implementation 'org.apache.commons:commons-compress:1.28.0'
dependabot[bot]a224ce22026-01-19 09:45:44 +000059 implementation 'me.tongfei:progressbar:0.10.2'
Marc Kupietzd4c6bd52025-11-17 22:18:23 +010060 implementation 'org.lz4:lz4-java:1.8.0'
Marc Kupietza92bacb2024-04-06 20:26:05 +020061
Marc Kupietzd8549e42025-11-16 17:23:04 +010062 // Fix XML APIs conflict - force resolution to the non-relocated version
dependabot[bot]76ae8f32025-11-21 10:56:44 +000063 implementation('xml-apis:xml-apis:2.0.2') {
64 because 'Avoid POM relocation warnings from xml-apis 2.0.2 -> 2.0.2'
Marc Kupietzd8549e42025-11-16 17:23:04 +010065 }
Marc Kupietz4f6ed422024-03-01 07:27:46 +010066}
67
Marc Kupietz9ba69852026-06-04 20:11:09 +020068// Target JVM 21 compatibility using whatever host JDK is available (minimum 21)
Marc Kupietz8d875cc2025-10-31 15:36:33 +010069java {
Marc Kupietz9ba69852026-06-04 20:11:09 +020070 sourceCompatibility = JavaVersion.VERSION_21
71 targetCompatibility = JavaVersion.VERSION_21
Marc Kupietz8d875cc2025-10-31 15:36:33 +010072}
73
Marc Kupietz64dce822025-11-02 14:39:39 +010074// For any existing Java source code
Marc Kupietz8d875cc2025-10-31 15:36:33 +010075tasks.withType(JavaCompile).configureEach {
76 options.release = 21
77}
78
79tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach {
80 kotlinOptions {
81 jvmTarget = "21"
Marc Kupietz64dce822025-11-02 14:39:39 +010082 // If available, this ensures consistent API targets similar to Java --release
Marc Kupietz8d875cc2025-10-31 15:36:33 +010083 // freeCompilerArgs += ["-Xjdk-release=21"]
84 }
85}
Marc Kupietz9da19db2024-04-01 11:06:51 +020086
Marc Kupietz64dce822025-11-02 14:39:39 +010087// Explicitly inherit version from root project
Marc Kupietzf13fc7b2025-10-31 17:28:21 +010088version = rootProject.version
89
Marc Kupietz4f6ed422024-03-01 07:27:46 +010090application {
91 // Define the main class for the application.
Marc Kupietz07c60d32025-01-21 19:32:48 +010092 mainClass = 'de.ids_mannheim.korapxmltools.KorapXmlToolKt'
Marc Kupietz4f6ed422024-03-01 07:27:46 +010093}
94
95jar {
Marc Kupietz64dce822025-11-02 14:39:39 +010096 // Mark standard JAR as "plain" to avoid conflicts with ShadowJar
Marc Kupietzf13fc7b2025-10-31 17:28:21 +010097 archiveClassifier.set('plain')
Marc Kupietz4f6ed422024-03-01 07:27:46 +010098 manifest.attributes(
99 'Class-Path': configurations.compileClasspath.collect { it.getName() }.join(' '),
Marc Kupietzde917592025-10-31 15:44:27 +0100100 'Main-Class': "de.ids_mannheim.korapxmltools.KorapXmlToolKt",
101 'Implementation-Title': rootProject.name,
102 'Implementation-Version': project.version
Marc Kupietz4f6ed422024-03-01 07:27:46 +0100103 )
Marc Kupietzf13fc7b2025-10-31 17:28:21 +0100104}
105
106shadowJar {
107 archiveBaseName.set('korapxmltool')
108 archiveClassifier.set('')
109 archiveVersion.set(project.version.toString())
110 manifest.attributes(
111 'Main-Class': "de.ids_mannheim.korapxmltools.KorapXmlToolKt",
112 'Implementation-Title': rootProject.name,
113 'Implementation-Version': project.version
114 )
115}
116
Marc Kupietz64dce822025-11-02 14:39:39 +0100117// Ensure that assemble also creates the ShadowJar
Marc Kupietzf13fc7b2025-10-31 17:28:21 +0100118tasks.named('assemble') {
119 dependsOn tasks.named('shadowJar')
120}
121
Marc Kupietz64dce822025-11-02 14:39:39 +0100122// Additionally create a symlink korapxmltool.jar to the current version for stable script paths
123tasks.register('createJarSymlink') {
124 dependsOn shadowJar
125 doLast {
126 def targetJar = shadowJar.archiveFile.get().asFile
127 def linkFile = new File(targetJar.parent, 'korapxmltool.jar')
128
129 // Remove existing symlink or file
130 if (linkFile.exists()) {
131 linkFile.delete()
132 }
133
134 // Create symlink (Java 7+ NIO)
135 try {
136 java.nio.file.Files.createSymbolicLink(
137 linkFile.toPath(),
138 java.nio.file.Paths.get(targetJar.name)
139 )
140 println "Created symlink: ${linkFile.name} -> ${targetJar.name}"
141 } catch (Exception e) {
142 // Fallback to copy on systems where symlinks aren't supported
143 println "Warning: Could not create symlink (${e.message}), copying instead"
144 java.nio.file.Files.copy(targetJar.toPath(), linkFile.toPath())
145 }
146 }
Marc Kupietzf13fc7b2025-10-31 17:28:21 +0100147}
148
Marc Kupietzfbfcd042025-11-16 13:33:32 +0100149// Concatenate shebang + shaded jar into an executable launcher
150tasks.register('assembleShebangExecutable') {
151 dependsOn shadowJar
152 inputs.file(rootProject.file("korapxmltool.shebang"))
Marc Kupietz1869f502025-11-16 21:31:12 +0100153 inputs.file(shadowJar.archiveFile)
154
155 def binDir = rootProject.file("build/bin")
156 def targetExec = new File(binDir, "korapxmltool")
Marc Kupietz481643b2025-11-19 12:27:32 +0100157 def krillExec = new File(binDir, "korapxml2krill")
Marc Kupietzcec41012025-11-19 13:48:48 +0100158 def conlluExec = new File(binDir, "korapxml2conllu")
Marc Kupietza2c33982025-11-19 18:19:46 +0100159 def conllu2korapxmlExec = new File(binDir, "conllu2korapxml")
Marc Kupietz1869f502025-11-16 21:31:12 +0100160 outputs.file(targetExec)
Marc Kupietz481643b2025-11-19 12:27:32 +0100161 outputs.file(krillExec)
Marc Kupietzcec41012025-11-19 13:48:48 +0100162 outputs.file(conlluExec)
Marc Kupietza2c33982025-11-19 18:19:46 +0100163 outputs.file(conllu2korapxmlExec)
Marc Kupietzfbfcd042025-11-16 13:33:32 +0100164
165 doLast {
166 def shebang = rootProject.file("korapxmltool.shebang")
167 if (!shebang.exists()) {
168 throw new GradleException("Missing shebang stub: ${shebang}")
169 }
170
Marc Kupietz1869f502025-11-16 21:31:12 +0100171 // Ensure bin directory exists
172 binDir.mkdirs()
173
Marc Kupietzfbfcd042025-11-16 13:33:32 +0100174 def targetJar = shadowJar.archiveFile.get().asFile
Marc Kupietzfbfcd042025-11-16 13:33:32 +0100175
Marc Kupietz481643b2025-11-19 12:27:32 +0100176 // Create main korapxmltool executable
Marc Kupietzfbfcd042025-11-16 13:33:32 +0100177 targetExec.withOutputStream { os ->
178 os << shebang.bytes
179 os << targetJar.bytes
180 }
Marc Kupietz05d3bbb2025-11-17 15:17:03 +0100181 targetExec.setExecutable(true, false)
Marc Kupietzfbfcd042025-11-16 13:33:32 +0100182 println "Created executable launcher: ${targetExec}"
Marc Kupietz481643b2025-11-19 12:27:32 +0100183
184 // Create korapxml2krill symlink for backward compatibility
185 if (krillExec.exists()) {
186 krillExec.delete()
187 }
188 try {
189 java.nio.file.Files.createSymbolicLink(
190 krillExec.toPath(),
191 java.nio.file.Paths.get("korapxmltool")
192 )
193 println "Created symlink: korapxml2krill -> korapxmltool"
194 } catch (Exception e) {
195 println "Warning: Could not create korapxml2krill symlink (${e.message}), copying instead"
196 java.nio.file.Files.copy(targetExec.toPath(), krillExec.toPath())
197 krillExec.setExecutable(true, false)
198 }
Marc Kupietzcec41012025-11-19 13:48:48 +0100199
200 // Create korapxml2conllu symlink for backward compatibility
201 if (conlluExec.exists()) {
202 conlluExec.delete()
203 }
204 try {
205 java.nio.file.Files.createSymbolicLink(
206 conlluExec.toPath(),
207 java.nio.file.Paths.get("korapxmltool")
208 )
209 println "Created symlink: korapxml2conllu -> korapxmltool"
210 } catch (Exception e) {
211 println "Warning: Could not create korapxml2conllu symlink (${e.message}), copying instead"
212 java.nio.file.Files.copy(targetExec.toPath(), conlluExec.toPath())
213 conlluExec.setExecutable(true, false)
214 }
Marc Kupietza2c33982025-11-19 18:19:46 +0100215
216 // Create conllu2korapxml symlink for CoNLL-U to KorAP XML ZIP conversion
217 if (conllu2korapxmlExec.exists()) {
218 conllu2korapxmlExec.delete()
219 }
220 try {
221 java.nio.file.Files.createSymbolicLink(
222 conllu2korapxmlExec.toPath(),
223 java.nio.file.Paths.get("korapxmltool")
224 )
225 println "Created symlink: conllu2korapxml -> korapxmltool"
226 } catch (Exception e) {
227 println "Warning: Could not create conllu2korapxml symlink (${e.message}), copying instead"
228 java.nio.file.Files.copy(targetExec.toPath(), conllu2korapxmlExec.toPath())
229 conllu2korapxmlExec.setExecutable(true, false)
230 }
Marc Kupietzfbfcd042025-11-16 13:33:32 +0100231 }
232}
233
Marc Kupietz1869f502025-11-16 21:31:12 +0100234tasks.named('assemble') {
235 dependsOn createJarSymlink
236 dependsOn assembleShebangExecutable
237}
238
Marc Kupietzf13fc7b2025-10-31 17:28:21 +0100239tasks.named('build') {
Marc Kupietz64dce822025-11-02 14:39:39 +0100240 dependsOn createJarSymlink
Marc Kupietzfbfcd042025-11-16 13:33:32 +0100241 dependsOn assembleShebangExecutable
Marc Kupietz4f6ed422024-03-01 07:27:46 +0100242}
243
244
245configurations {
246 runtimeLib.extendsFrom implementation
247}