blob: ac3cd4fb963c2247e3977b108d9e580150fb8afc [file] [log] [blame]
Marc Kupietz4f6ed422024-03-01 07:27:46 +01001plugins {
2 // Apply the org.jetbrains.kotlin.jvm Plugin to add support for Kotlin.
Marc Kupietzde917592025-10-31 15:44:27 +01003 id 'org.jetbrains.kotlin.jvm' version '2.2.21'
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 Kupietz56a45562024-03-20 20:18:08 +010012 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 Kupietz47b43c32024-03-27 20:43:32 +010019}
20
Marc Kupietz4f6ed422024-03-01 07:27:46 +010021dependencies {
22 // Align versions of all Kotlin components
23 implementation platform('org.jetbrains.kotlin:kotlin-bom')
24
25 // Use the Kotlin JDK 8 standard library.
26 implementation 'org.jetbrains.kotlin:kotlin-stdlib'
Marc Kupietzfc18d282025-08-31 12:07:46 +020027 implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.10.2'
Marc Kupietz4f6ed422024-03-01 07:27:46 +010028
29 // This dependency is used by the application.
Marc Kupietzde917592025-10-31 15:44:27 +010030 implementation 'com.google.guava:guava:33.5.0-jre'
Marc Kupietz4f6ed422024-03-01 07:27:46 +010031
Marc Kupietz31122362024-03-02 11:13:37 +010032
Marc Kupietzfc18d282025-08-31 12:07:46 +020033 implementation ("info.picocli:picocli:4.7.7")
Marc Kupietz31122362024-03-02 11:13:37 +010034
Marc Kupietz4f6ed422024-03-01 07:27:46 +010035 // Use the Kotlin test library.
36 testImplementation 'org.jetbrains.kotlin:kotlin-test'
37
38 // Use the Kotlin JUnit integration.
39 testImplementation 'org.jetbrains.kotlin:kotlin-test-junit'
Marc Kupietzde917592025-10-31 15:44:27 +010040 testImplementation "org.jetbrains.kotlin:kotlin-test:2.2.21"
Marc Kupietz0c6e8772024-03-19 07:03:07 +010041
Marc Kupietz1465ce22024-03-26 09:51:17 +010042 implementation 'com.github.kupietz:cistern:v1.0.4'
Marc Kupietzaf682a42024-03-22 06:51:55 +010043 implementation 'org.maltparser:maltparser:1.9.2'
Marc Kupietzde917592025-10-31 15:44:27 +010044 implementation 'org.apache.opennlp:opennlp-tools:2.5.6'
Marc Kupietzddea0c02025-11-15 19:53:38 +010045 implementation 'edu.stanford.nlp:stanford-corenlp:3.9.2'
Marc Kupietzfc18d282025-08-31 12:07:46 +020046 implementation 'org.slf4j:slf4j-simple:2.0.17'
Marc Kupietz916bdfe2024-09-20 09:02:57 +020047 implementation 'org.apache.ant:ant:1.10.15'
Marc Kupietzfc18d282025-08-31 12:07:46 +020048 implementation 'org.apache.commons:commons-compress:1.28.0'
Marc Kupietzd698f0e2025-11-01 20:00:07 +010049 implementation 'me.tongfei:progressbar:0.10.1'
Marc Kupietzd4c6bd52025-11-17 22:18:23 +010050 implementation 'org.lz4:lz4-java:1.8.0'
Marc Kupietza92bacb2024-04-06 20:26:05 +020051
Marc Kupietzd8549e42025-11-16 17:23:04 +010052 // Fix XML APIs conflict - force resolution to the non-relocated version
53 implementation('xml-apis:xml-apis:1.0.b2') {
54 because 'Avoid POM relocation warnings from xml-apis 2.0.2 -> 1.0.b2'
55 }
Marc Kupietz4f6ed422024-03-01 07:27:46 +010056}
57
Marc Kupietz64dce822025-11-02 14:39:39 +010058// Enforce JDK 21 Toolchain and Bytecode-Level 21
Marc Kupietz8d875cc2025-10-31 15:36:33 +010059java {
60 toolchain {
61 languageVersion = JavaLanguageVersion.of(21)
62 }
63}
Marc Kupietz4f6ed422024-03-01 07:27:46 +010064
Marc Kupietz8d875cc2025-10-31 15:36:33 +010065kotlin {
66 jvmToolchain(21)
67}
68
Marc Kupietz64dce822025-11-02 14:39:39 +010069// For any existing Java source code
Marc Kupietz8d875cc2025-10-31 15:36:33 +010070tasks.withType(JavaCompile).configureEach {
71 options.release = 21
72}
73
74tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach {
75 kotlinOptions {
76 jvmTarget = "21"
Marc Kupietz64dce822025-11-02 14:39:39 +010077 // If available, this ensures consistent API targets similar to Java --release
Marc Kupietz8d875cc2025-10-31 15:36:33 +010078 // freeCompilerArgs += ["-Xjdk-release=21"]
79 }
80}
Marc Kupietz9da19db2024-04-01 11:06:51 +020081
Marc Kupietz64dce822025-11-02 14:39:39 +010082// Explicitly inherit version from root project
Marc Kupietzf13fc7b2025-10-31 17:28:21 +010083version = rootProject.version
84
Marc Kupietz4f6ed422024-03-01 07:27:46 +010085application {
86 // Define the main class for the application.
Marc Kupietz07c60d32025-01-21 19:32:48 +010087 mainClass = 'de.ids_mannheim.korapxmltools.KorapXmlToolKt'
Marc Kupietz4f6ed422024-03-01 07:27:46 +010088}
89
90jar {
Marc Kupietz64dce822025-11-02 14:39:39 +010091 // Mark standard JAR as "plain" to avoid conflicts with ShadowJar
Marc Kupietzf13fc7b2025-10-31 17:28:21 +010092 archiveClassifier.set('plain')
Marc Kupietz4f6ed422024-03-01 07:27:46 +010093 manifest.attributes(
94 'Class-Path': configurations.compileClasspath.collect { it.getName() }.join(' '),
Marc Kupietzde917592025-10-31 15:44:27 +010095 'Main-Class': "de.ids_mannheim.korapxmltools.KorapXmlToolKt",
96 'Implementation-Title': rootProject.name,
97 'Implementation-Version': project.version
Marc Kupietz4f6ed422024-03-01 07:27:46 +010098 )
Marc Kupietzf13fc7b2025-10-31 17:28:21 +010099}
100
101shadowJar {
102 archiveBaseName.set('korapxmltool')
103 archiveClassifier.set('')
104 archiveVersion.set(project.version.toString())
105 manifest.attributes(
106 'Main-Class': "de.ids_mannheim.korapxmltools.KorapXmlToolKt",
107 'Implementation-Title': rootProject.name,
108 'Implementation-Version': project.version
109 )
110}
111
Marc Kupietz64dce822025-11-02 14:39:39 +0100112// Ensure that assemble also creates the ShadowJar
Marc Kupietzf13fc7b2025-10-31 17:28:21 +0100113tasks.named('assemble') {
114 dependsOn tasks.named('shadowJar')
115}
116
Marc Kupietz64dce822025-11-02 14:39:39 +0100117// Additionally create a symlink korapxmltool.jar to the current version for stable script paths
118tasks.register('createJarSymlink') {
119 dependsOn shadowJar
120 doLast {
121 def targetJar = shadowJar.archiveFile.get().asFile
122 def linkFile = new File(targetJar.parent, 'korapxmltool.jar')
123
124 // Remove existing symlink or file
125 if (linkFile.exists()) {
126 linkFile.delete()
127 }
128
129 // Create symlink (Java 7+ NIO)
130 try {
131 java.nio.file.Files.createSymbolicLink(
132 linkFile.toPath(),
133 java.nio.file.Paths.get(targetJar.name)
134 )
135 println "Created symlink: ${linkFile.name} -> ${targetJar.name}"
136 } catch (Exception e) {
137 // Fallback to copy on systems where symlinks aren't supported
138 println "Warning: Could not create symlink (${e.message}), copying instead"
139 java.nio.file.Files.copy(targetJar.toPath(), linkFile.toPath())
140 }
141 }
Marc Kupietzf13fc7b2025-10-31 17:28:21 +0100142}
143
Marc Kupietzfbfcd042025-11-16 13:33:32 +0100144// Concatenate shebang + shaded jar into an executable launcher
145tasks.register('assembleShebangExecutable') {
146 dependsOn shadowJar
147 inputs.file(rootProject.file("korapxmltool.shebang"))
Marc Kupietz1869f502025-11-16 21:31:12 +0100148 inputs.file(shadowJar.archiveFile)
149
150 def binDir = rootProject.file("build/bin")
151 def targetExec = new File(binDir, "korapxmltool")
Marc Kupietz481643b2025-11-19 12:27:32 +0100152 def krillExec = new File(binDir, "korapxml2krill")
Marc Kupietzcec41012025-11-19 13:48:48 +0100153 def conlluExec = new File(binDir, "korapxml2conllu")
Marc Kupietza2c33982025-11-19 18:19:46 +0100154 def conllu2korapxmlExec = new File(binDir, "conllu2korapxml")
Marc Kupietz1869f502025-11-16 21:31:12 +0100155 outputs.file(targetExec)
Marc Kupietz481643b2025-11-19 12:27:32 +0100156 outputs.file(krillExec)
Marc Kupietzcec41012025-11-19 13:48:48 +0100157 outputs.file(conlluExec)
Marc Kupietza2c33982025-11-19 18:19:46 +0100158 outputs.file(conllu2korapxmlExec)
Marc Kupietzfbfcd042025-11-16 13:33:32 +0100159
160 doLast {
161 def shebang = rootProject.file("korapxmltool.shebang")
162 if (!shebang.exists()) {
163 throw new GradleException("Missing shebang stub: ${shebang}")
164 }
165
Marc Kupietz1869f502025-11-16 21:31:12 +0100166 // Ensure bin directory exists
167 binDir.mkdirs()
168
Marc Kupietzfbfcd042025-11-16 13:33:32 +0100169 def targetJar = shadowJar.archiveFile.get().asFile
Marc Kupietzfbfcd042025-11-16 13:33:32 +0100170
Marc Kupietz481643b2025-11-19 12:27:32 +0100171 // Create main korapxmltool executable
Marc Kupietzfbfcd042025-11-16 13:33:32 +0100172 targetExec.withOutputStream { os ->
173 os << shebang.bytes
174 os << targetJar.bytes
175 }
Marc Kupietz05d3bbb2025-11-17 15:17:03 +0100176 targetExec.setExecutable(true, false)
Marc Kupietzfbfcd042025-11-16 13:33:32 +0100177 println "Created executable launcher: ${targetExec}"
Marc Kupietz481643b2025-11-19 12:27:32 +0100178
179 // Create korapxml2krill symlink for backward compatibility
180 if (krillExec.exists()) {
181 krillExec.delete()
182 }
183 try {
184 java.nio.file.Files.createSymbolicLink(
185 krillExec.toPath(),
186 java.nio.file.Paths.get("korapxmltool")
187 )
188 println "Created symlink: korapxml2krill -> korapxmltool"
189 } catch (Exception e) {
190 println "Warning: Could not create korapxml2krill symlink (${e.message}), copying instead"
191 java.nio.file.Files.copy(targetExec.toPath(), krillExec.toPath())
192 krillExec.setExecutable(true, false)
193 }
Marc Kupietzcec41012025-11-19 13:48:48 +0100194
195 // Create korapxml2conllu symlink for backward compatibility
196 if (conlluExec.exists()) {
197 conlluExec.delete()
198 }
199 try {
200 java.nio.file.Files.createSymbolicLink(
201 conlluExec.toPath(),
202 java.nio.file.Paths.get("korapxmltool")
203 )
204 println "Created symlink: korapxml2conllu -> korapxmltool"
205 } catch (Exception e) {
206 println "Warning: Could not create korapxml2conllu symlink (${e.message}), copying instead"
207 java.nio.file.Files.copy(targetExec.toPath(), conlluExec.toPath())
208 conlluExec.setExecutable(true, false)
209 }
Marc Kupietza2c33982025-11-19 18:19:46 +0100210
211 // Create conllu2korapxml symlink for CoNLL-U to KorAP XML ZIP conversion
212 if (conllu2korapxmlExec.exists()) {
213 conllu2korapxmlExec.delete()
214 }
215 try {
216 java.nio.file.Files.createSymbolicLink(
217 conllu2korapxmlExec.toPath(),
218 java.nio.file.Paths.get("korapxmltool")
219 )
220 println "Created symlink: conllu2korapxml -> korapxmltool"
221 } catch (Exception e) {
222 println "Warning: Could not create conllu2korapxml symlink (${e.message}), copying instead"
223 java.nio.file.Files.copy(targetExec.toPath(), conllu2korapxmlExec.toPath())
224 conllu2korapxmlExec.setExecutable(true, false)
225 }
Marc Kupietzfbfcd042025-11-16 13:33:32 +0100226 }
227}
228
Marc Kupietz1869f502025-11-16 21:31:12 +0100229tasks.named('assemble') {
230 dependsOn createJarSymlink
231 dependsOn assembleShebangExecutable
232}
233
Marc Kupietzf13fc7b2025-10-31 17:28:21 +0100234tasks.named('build') {
Marc Kupietz64dce822025-11-02 14:39:39 +0100235 dependsOn createJarSymlink
Marc Kupietzfbfcd042025-11-16 13:33:32 +0100236 dependsOn assembleShebangExecutable
Marc Kupietz4f6ed422024-03-01 07:27:46 +0100237}
238
239
240configurations {
241 runtimeLib.extendsFrom implementation
242}