blob: 93819ce5d972cd97d5eac26cc6b33a64b7c8d238 [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 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'
Marc Kupietzde917592025-10-31 15:44:27 +010044 testImplementation "org.jetbrains.kotlin:kotlin-test:2.2.21"
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]f36c2cc2025-11-21 10:56:51 +000048 implementation 'org.apache.opennlp:opennlp-tools:2.5.6.1'
Marc Kupietzddea0c02025-11-15 19:53:38 +010049 implementation 'edu.stanford.nlp:stanford-corenlp:3.9.2'
Marc Kupietzfc18d282025-08-31 12:07:46 +020050 implementation 'org.slf4j:slf4j-simple:2.0.17'
Marc Kupietz916bdfe2024-09-20 09:02:57 +020051 implementation 'org.apache.ant:ant:1.10.15'
Marc Kupietzfc18d282025-08-31 12:07:46 +020052 implementation 'org.apache.commons:commons-compress:1.28.0'
Marc Kupietzd698f0e2025-11-01 20:00:07 +010053 implementation 'me.tongfei:progressbar:0.10.1'
Marc Kupietzd4c6bd52025-11-17 22:18:23 +010054 implementation 'org.lz4:lz4-java:1.8.0'
Marc Kupietza92bacb2024-04-06 20:26:05 +020055
Marc Kupietzd8549e42025-11-16 17:23:04 +010056 // Fix XML APIs conflict - force resolution to the non-relocated version
dependabot[bot]76ae8f32025-11-21 10:56:44 +000057 implementation('xml-apis:xml-apis:2.0.2') {
58 because 'Avoid POM relocation warnings from xml-apis 2.0.2 -> 2.0.2'
Marc Kupietzd8549e42025-11-16 17:23:04 +010059 }
Marc Kupietz4f6ed422024-03-01 07:27:46 +010060}
61
Marc Kupietz64dce822025-11-02 14:39:39 +010062// Enforce JDK 21 Toolchain and Bytecode-Level 21
Marc Kupietz8d875cc2025-10-31 15:36:33 +010063java {
64 toolchain {
65 languageVersion = JavaLanguageVersion.of(21)
66 }
67}
Marc Kupietz4f6ed422024-03-01 07:27:46 +010068
Marc Kupietz8d875cc2025-10-31 15:36:33 +010069kotlin {
70 jvmToolchain(21)
71}
72
Marc Kupietz64dce822025-11-02 14:39:39 +010073// For any existing Java source code
Marc Kupietz8d875cc2025-10-31 15:36:33 +010074tasks.withType(JavaCompile).configureEach {
75 options.release = 21
76}
77
78tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach {
79 kotlinOptions {
80 jvmTarget = "21"
Marc Kupietz64dce822025-11-02 14:39:39 +010081 // If available, this ensures consistent API targets similar to Java --release
Marc Kupietz8d875cc2025-10-31 15:36:33 +010082 // freeCompilerArgs += ["-Xjdk-release=21"]
83 }
84}
Marc Kupietz9da19db2024-04-01 11:06:51 +020085
Marc Kupietz64dce822025-11-02 14:39:39 +010086// Explicitly inherit version from root project
Marc Kupietzf13fc7b2025-10-31 17:28:21 +010087version = rootProject.version
88
Marc Kupietz4f6ed422024-03-01 07:27:46 +010089application {
90 // Define the main class for the application.
Marc Kupietz07c60d32025-01-21 19:32:48 +010091 mainClass = 'de.ids_mannheim.korapxmltools.KorapXmlToolKt'
Marc Kupietz4f6ed422024-03-01 07:27:46 +010092}
93
94jar {
Marc Kupietz64dce822025-11-02 14:39:39 +010095 // Mark standard JAR as "plain" to avoid conflicts with ShadowJar
Marc Kupietzf13fc7b2025-10-31 17:28:21 +010096 archiveClassifier.set('plain')
Marc Kupietz4f6ed422024-03-01 07:27:46 +010097 manifest.attributes(
98 'Class-Path': configurations.compileClasspath.collect { it.getName() }.join(' '),
Marc Kupietzde917592025-10-31 15:44:27 +010099 'Main-Class': "de.ids_mannheim.korapxmltools.KorapXmlToolKt",
100 'Implementation-Title': rootProject.name,
101 'Implementation-Version': project.version
Marc Kupietz4f6ed422024-03-01 07:27:46 +0100102 )
Marc Kupietzf13fc7b2025-10-31 17:28:21 +0100103}
104
105shadowJar {
106 archiveBaseName.set('korapxmltool')
107 archiveClassifier.set('')
108 archiveVersion.set(project.version.toString())
109 manifest.attributes(
110 'Main-Class': "de.ids_mannheim.korapxmltools.KorapXmlToolKt",
111 'Implementation-Title': rootProject.name,
112 'Implementation-Version': project.version
113 )
114}
115
Marc Kupietz64dce822025-11-02 14:39:39 +0100116// Ensure that assemble also creates the ShadowJar
Marc Kupietzf13fc7b2025-10-31 17:28:21 +0100117tasks.named('assemble') {
118 dependsOn tasks.named('shadowJar')
119}
120
Marc Kupietz64dce822025-11-02 14:39:39 +0100121// Additionally create a symlink korapxmltool.jar to the current version for stable script paths
122tasks.register('createJarSymlink') {
123 dependsOn shadowJar
124 doLast {
125 def targetJar = shadowJar.archiveFile.get().asFile
126 def linkFile = new File(targetJar.parent, 'korapxmltool.jar')
127
128 // Remove existing symlink or file
129 if (linkFile.exists()) {
130 linkFile.delete()
131 }
132
133 // Create symlink (Java 7+ NIO)
134 try {
135 java.nio.file.Files.createSymbolicLink(
136 linkFile.toPath(),
137 java.nio.file.Paths.get(targetJar.name)
138 )
139 println "Created symlink: ${linkFile.name} -> ${targetJar.name}"
140 } catch (Exception e) {
141 // Fallback to copy on systems where symlinks aren't supported
142 println "Warning: Could not create symlink (${e.message}), copying instead"
143 java.nio.file.Files.copy(targetJar.toPath(), linkFile.toPath())
144 }
145 }
Marc Kupietzf13fc7b2025-10-31 17:28:21 +0100146}
147
Marc Kupietzfbfcd042025-11-16 13:33:32 +0100148// Concatenate shebang + shaded jar into an executable launcher
149tasks.register('assembleShebangExecutable') {
150 dependsOn shadowJar
151 inputs.file(rootProject.file("korapxmltool.shebang"))
Marc Kupietz1869f502025-11-16 21:31:12 +0100152 inputs.file(shadowJar.archiveFile)
153
154 def binDir = rootProject.file("build/bin")
155 def targetExec = new File(binDir, "korapxmltool")
Marc Kupietz481643b2025-11-19 12:27:32 +0100156 def krillExec = new File(binDir, "korapxml2krill")
Marc Kupietzcec41012025-11-19 13:48:48 +0100157 def conlluExec = new File(binDir, "korapxml2conllu")
Marc Kupietza2c33982025-11-19 18:19:46 +0100158 def conllu2korapxmlExec = new File(binDir, "conllu2korapxml")
Marc Kupietz1869f502025-11-16 21:31:12 +0100159 outputs.file(targetExec)
Marc Kupietz481643b2025-11-19 12:27:32 +0100160 outputs.file(krillExec)
Marc Kupietzcec41012025-11-19 13:48:48 +0100161 outputs.file(conlluExec)
Marc Kupietza2c33982025-11-19 18:19:46 +0100162 outputs.file(conllu2korapxmlExec)
Marc Kupietzfbfcd042025-11-16 13:33:32 +0100163
164 doLast {
165 def shebang = rootProject.file("korapxmltool.shebang")
166 if (!shebang.exists()) {
167 throw new GradleException("Missing shebang stub: ${shebang}")
168 }
169
Marc Kupietz1869f502025-11-16 21:31:12 +0100170 // Ensure bin directory exists
171 binDir.mkdirs()
172
Marc Kupietzfbfcd042025-11-16 13:33:32 +0100173 def targetJar = shadowJar.archiveFile.get().asFile
Marc Kupietzfbfcd042025-11-16 13:33:32 +0100174
Marc Kupietz481643b2025-11-19 12:27:32 +0100175 // Create main korapxmltool executable
Marc Kupietzfbfcd042025-11-16 13:33:32 +0100176 targetExec.withOutputStream { os ->
177 os << shebang.bytes
178 os << targetJar.bytes
179 }
Marc Kupietz05d3bbb2025-11-17 15:17:03 +0100180 targetExec.setExecutable(true, false)
Marc Kupietzfbfcd042025-11-16 13:33:32 +0100181 println "Created executable launcher: ${targetExec}"
Marc Kupietz481643b2025-11-19 12:27:32 +0100182
183 // Create korapxml2krill symlink for backward compatibility
184 if (krillExec.exists()) {
185 krillExec.delete()
186 }
187 try {
188 java.nio.file.Files.createSymbolicLink(
189 krillExec.toPath(),
190 java.nio.file.Paths.get("korapxmltool")
191 )
192 println "Created symlink: korapxml2krill -> korapxmltool"
193 } catch (Exception e) {
194 println "Warning: Could not create korapxml2krill symlink (${e.message}), copying instead"
195 java.nio.file.Files.copy(targetExec.toPath(), krillExec.toPath())
196 krillExec.setExecutable(true, false)
197 }
Marc Kupietzcec41012025-11-19 13:48:48 +0100198
199 // Create korapxml2conllu symlink for backward compatibility
200 if (conlluExec.exists()) {
201 conlluExec.delete()
202 }
203 try {
204 java.nio.file.Files.createSymbolicLink(
205 conlluExec.toPath(),
206 java.nio.file.Paths.get("korapxmltool")
207 )
208 println "Created symlink: korapxml2conllu -> korapxmltool"
209 } catch (Exception e) {
210 println "Warning: Could not create korapxml2conllu symlink (${e.message}), copying instead"
211 java.nio.file.Files.copy(targetExec.toPath(), conlluExec.toPath())
212 conlluExec.setExecutable(true, false)
213 }
Marc Kupietza2c33982025-11-19 18:19:46 +0100214
215 // Create conllu2korapxml symlink for CoNLL-U to KorAP XML ZIP conversion
216 if (conllu2korapxmlExec.exists()) {
217 conllu2korapxmlExec.delete()
218 }
219 try {
220 java.nio.file.Files.createSymbolicLink(
221 conllu2korapxmlExec.toPath(),
222 java.nio.file.Paths.get("korapxmltool")
223 )
224 println "Created symlink: conllu2korapxml -> korapxmltool"
225 } catch (Exception e) {
226 println "Warning: Could not create conllu2korapxml symlink (${e.message}), copying instead"
227 java.nio.file.Files.copy(targetExec.toPath(), conllu2korapxmlExec.toPath())
228 conllu2korapxmlExec.setExecutable(true, false)
229 }
Marc Kupietzfbfcd042025-11-16 13:33:32 +0100230 }
231}
232
Marc Kupietz1869f502025-11-16 21:31:12 +0100233tasks.named('assemble') {
234 dependsOn createJarSymlink
235 dependsOn assembleShebangExecutable
236}
237
Marc Kupietzf13fc7b2025-10-31 17:28:21 +0100238tasks.named('build') {
Marc Kupietz64dce822025-11-02 14:39:39 +0100239 dependsOn createJarSymlink
Marc Kupietzfbfcd042025-11-16 13:33:32 +0100240 dependsOn assembleShebangExecutable
Marc Kupietz4f6ed422024-03-01 07:27:46 +0100241}
242
243
244configurations {
245 runtimeLib.extendsFrom implementation
246}