| Marc Kupietz | 4f6ed42 | 2024-03-01 07:27:46 +0100 | [diff] [blame] | 1 | plugins { |
| 2 | // Apply the org.jetbrains.kotlin.jvm Plugin to add support for Kotlin. |
| Marc Kupietz | de91759 | 2025-10-31 15:44:27 +0100 | [diff] [blame] | 3 | id 'org.jetbrains.kotlin.jvm' version '2.2.21' |
| Marc Kupietz | 4f6ed42 | 2024-03-01 07:27:46 +0100 | [diff] [blame] | 4 | |
| 5 | // Apply the application plugin to add support for building a CLI application in Java. |
| 6 | id 'application' |
| Marc Kupietz | 1b59599 | 2024-03-01 14:54:30 +0100 | [diff] [blame] | 7 | id 'com.github.johnrengelman.shadow' version '8.1.1' |
| Marc Kupietz | 4f6ed42 | 2024-03-01 07:27:46 +0100 | [diff] [blame] | 8 | } |
| 9 | |
| Marc Kupietz | 4f6ed42 | 2024-03-01 07:27:46 +0100 | [diff] [blame] | 10 | repositories { |
| Marc Kupietz | 4f6ed42 | 2024-03-01 07:27:46 +0100 | [diff] [blame] | 11 | mavenCentral() |
| Marc Kupietz | 56a4556 | 2024-03-20 20:18:08 +0100 | [diff] [blame] | 12 | maven { url 'https://jitpack.io' } |
| Marc Kupietz | 4f6ed42 | 2024-03-01 07:27:46 +0100 | [diff] [blame] | 13 | } |
| 14 | |
| Marc Kupietz | 47b43c3 | 2024-03-27 20:43:32 +0100 | [diff] [blame] | 15 | test { |
| Marc Kupietz | fc18d28 | 2025-08-31 12:07:46 +0200 | [diff] [blame] | 16 | minHeapSize = "512m" |
| 17 | maxHeapSize = "4096m" |
| 18 | jvmArgs '-XX:MaxMetaspaceSize=1024m' |
| Marc Kupietz | 47b43c3 | 2024-03-27 20:43:32 +0100 | [diff] [blame] | 19 | } |
| 20 | |
| Marc Kupietz | 4f6ed42 | 2024-03-01 07:27:46 +0100 | [diff] [blame] | 21 | dependencies { |
| 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 Kupietz | fc18d28 | 2025-08-31 12:07:46 +0200 | [diff] [blame] | 27 | implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.10.2' |
| Marc Kupietz | 4f6ed42 | 2024-03-01 07:27:46 +0100 | [diff] [blame] | 28 | |
| 29 | // This dependency is used by the application. |
| Marc Kupietz | de91759 | 2025-10-31 15:44:27 +0100 | [diff] [blame] | 30 | implementation 'com.google.guava:guava:33.5.0-jre' |
| Marc Kupietz | 4f6ed42 | 2024-03-01 07:27:46 +0100 | [diff] [blame] | 31 | |
| Marc Kupietz | 3112236 | 2024-03-02 11:13:37 +0100 | [diff] [blame] | 32 | |
| Marc Kupietz | fc18d28 | 2025-08-31 12:07:46 +0200 | [diff] [blame] | 33 | implementation ("info.picocli:picocli:4.7.7") |
| Marc Kupietz | 3112236 | 2024-03-02 11:13:37 +0100 | [diff] [blame] | 34 | |
| Marc Kupietz | 4f6ed42 | 2024-03-01 07:27:46 +0100 | [diff] [blame] | 35 | // 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 Kupietz | de91759 | 2025-10-31 15:44:27 +0100 | [diff] [blame] | 40 | testImplementation "org.jetbrains.kotlin:kotlin-test:2.2.21" |
| Marc Kupietz | 0c6e877 | 2024-03-19 07:03:07 +0100 | [diff] [blame] | 41 | |
| Marc Kupietz | 1465ce2 | 2024-03-26 09:51:17 +0100 | [diff] [blame] | 42 | implementation 'com.github.kupietz:cistern:v1.0.4' |
| Marc Kupietz | af682a4 | 2024-03-22 06:51:55 +0100 | [diff] [blame] | 43 | implementation 'org.maltparser:maltparser:1.9.2' |
| Marc Kupietz | de91759 | 2025-10-31 15:44:27 +0100 | [diff] [blame] | 44 | implementation 'org.apache.opennlp:opennlp-tools:2.5.6' |
| Marc Kupietz | ddea0c0 | 2025-11-15 19:53:38 +0100 | [diff] [blame] | 45 | implementation 'edu.stanford.nlp:stanford-corenlp:3.9.2' |
| Marc Kupietz | fc18d28 | 2025-08-31 12:07:46 +0200 | [diff] [blame] | 46 | implementation 'org.slf4j:slf4j-simple:2.0.17' |
| Marc Kupietz | 916bdfe | 2024-09-20 09:02:57 +0200 | [diff] [blame] | 47 | implementation 'org.apache.ant:ant:1.10.15' |
| Marc Kupietz | fc18d28 | 2025-08-31 12:07:46 +0200 | [diff] [blame] | 48 | implementation 'org.apache.commons:commons-compress:1.28.0' |
| Marc Kupietz | d698f0e | 2025-11-01 20:00:07 +0100 | [diff] [blame] | 49 | implementation 'me.tongfei:progressbar:0.10.1' |
| Marc Kupietz | a92bacb | 2024-04-06 20:26:05 +0200 | [diff] [blame] | 50 | |
| Marc Kupietz | d8549e4 | 2025-11-16 17:23:04 +0100 | [diff] [blame] | 51 | // Fix XML APIs conflict - force resolution to the non-relocated version |
| 52 | implementation('xml-apis:xml-apis:1.0.b2') { |
| 53 | because 'Avoid POM relocation warnings from xml-apis 2.0.2 -> 1.0.b2' |
| 54 | } |
| Marc Kupietz | 4f6ed42 | 2024-03-01 07:27:46 +0100 | [diff] [blame] | 55 | } |
| 56 | |
| Marc Kupietz | 64dce82 | 2025-11-02 14:39:39 +0100 | [diff] [blame] | 57 | // Enforce JDK 21 Toolchain and Bytecode-Level 21 |
| Marc Kupietz | 8d875cc | 2025-10-31 15:36:33 +0100 | [diff] [blame] | 58 | java { |
| 59 | toolchain { |
| 60 | languageVersion = JavaLanguageVersion.of(21) |
| 61 | } |
| 62 | } |
| Marc Kupietz | 4f6ed42 | 2024-03-01 07:27:46 +0100 | [diff] [blame] | 63 | |
| Marc Kupietz | 8d875cc | 2025-10-31 15:36:33 +0100 | [diff] [blame] | 64 | kotlin { |
| 65 | jvmToolchain(21) |
| 66 | } |
| 67 | |
| Marc Kupietz | 64dce82 | 2025-11-02 14:39:39 +0100 | [diff] [blame] | 68 | // For any existing Java source code |
| Marc Kupietz | 8d875cc | 2025-10-31 15:36:33 +0100 | [diff] [blame] | 69 | tasks.withType(JavaCompile).configureEach { |
| 70 | options.release = 21 |
| 71 | } |
| 72 | |
| 73 | tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach { |
| 74 | kotlinOptions { |
| 75 | jvmTarget = "21" |
| Marc Kupietz | 64dce82 | 2025-11-02 14:39:39 +0100 | [diff] [blame] | 76 | // If available, this ensures consistent API targets similar to Java --release |
| Marc Kupietz | 8d875cc | 2025-10-31 15:36:33 +0100 | [diff] [blame] | 77 | // freeCompilerArgs += ["-Xjdk-release=21"] |
| 78 | } |
| 79 | } |
| Marc Kupietz | 9da19db | 2024-04-01 11:06:51 +0200 | [diff] [blame] | 80 | |
| Marc Kupietz | 64dce82 | 2025-11-02 14:39:39 +0100 | [diff] [blame] | 81 | // Explicitly inherit version from root project |
| Marc Kupietz | f13fc7b | 2025-10-31 17:28:21 +0100 | [diff] [blame] | 82 | version = rootProject.version |
| 83 | |
| Marc Kupietz | 4f6ed42 | 2024-03-01 07:27:46 +0100 | [diff] [blame] | 84 | application { |
| 85 | // Define the main class for the application. |
| Marc Kupietz | 07c60d3 | 2025-01-21 19:32:48 +0100 | [diff] [blame] | 86 | mainClass = 'de.ids_mannheim.korapxmltools.KorapXmlToolKt' |
| Marc Kupietz | 4f6ed42 | 2024-03-01 07:27:46 +0100 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | jar { |
| Marc Kupietz | 64dce82 | 2025-11-02 14:39:39 +0100 | [diff] [blame] | 90 | // Mark standard JAR as "plain" to avoid conflicts with ShadowJar |
| Marc Kupietz | f13fc7b | 2025-10-31 17:28:21 +0100 | [diff] [blame] | 91 | archiveClassifier.set('plain') |
| Marc Kupietz | 4f6ed42 | 2024-03-01 07:27:46 +0100 | [diff] [blame] | 92 | manifest.attributes( |
| 93 | 'Class-Path': configurations.compileClasspath.collect { it.getName() }.join(' '), |
| Marc Kupietz | de91759 | 2025-10-31 15:44:27 +0100 | [diff] [blame] | 94 | 'Main-Class': "de.ids_mannheim.korapxmltools.KorapXmlToolKt", |
| 95 | 'Implementation-Title': rootProject.name, |
| 96 | 'Implementation-Version': project.version |
| Marc Kupietz | 4f6ed42 | 2024-03-01 07:27:46 +0100 | [diff] [blame] | 97 | ) |
| Marc Kupietz | f13fc7b | 2025-10-31 17:28:21 +0100 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | shadowJar { |
| 101 | archiveBaseName.set('korapxmltool') |
| 102 | archiveClassifier.set('') |
| 103 | archiveVersion.set(project.version.toString()) |
| 104 | manifest.attributes( |
| 105 | 'Main-Class': "de.ids_mannheim.korapxmltools.KorapXmlToolKt", |
| 106 | 'Implementation-Title': rootProject.name, |
| 107 | 'Implementation-Version': project.version |
| 108 | ) |
| 109 | } |
| 110 | |
| Marc Kupietz | 64dce82 | 2025-11-02 14:39:39 +0100 | [diff] [blame] | 111 | // Ensure that assemble also creates the ShadowJar |
| Marc Kupietz | f13fc7b | 2025-10-31 17:28:21 +0100 | [diff] [blame] | 112 | tasks.named('assemble') { |
| 113 | dependsOn tasks.named('shadowJar') |
| 114 | } |
| 115 | |
| Marc Kupietz | 64dce82 | 2025-11-02 14:39:39 +0100 | [diff] [blame] | 116 | // Additionally create a symlink korapxmltool.jar to the current version for stable script paths |
| 117 | tasks.register('createJarSymlink') { |
| 118 | dependsOn shadowJar |
| 119 | doLast { |
| 120 | def targetJar = shadowJar.archiveFile.get().asFile |
| 121 | def linkFile = new File(targetJar.parent, 'korapxmltool.jar') |
| 122 | |
| 123 | // Remove existing symlink or file |
| 124 | if (linkFile.exists()) { |
| 125 | linkFile.delete() |
| 126 | } |
| 127 | |
| 128 | // Create symlink (Java 7+ NIO) |
| 129 | try { |
| 130 | java.nio.file.Files.createSymbolicLink( |
| 131 | linkFile.toPath(), |
| 132 | java.nio.file.Paths.get(targetJar.name) |
| 133 | ) |
| 134 | println "Created symlink: ${linkFile.name} -> ${targetJar.name}" |
| 135 | } catch (Exception e) { |
| 136 | // Fallback to copy on systems where symlinks aren't supported |
| 137 | println "Warning: Could not create symlink (${e.message}), copying instead" |
| 138 | java.nio.file.Files.copy(targetJar.toPath(), linkFile.toPath()) |
| 139 | } |
| 140 | } |
| Marc Kupietz | f13fc7b | 2025-10-31 17:28:21 +0100 | [diff] [blame] | 141 | } |
| 142 | |
| Marc Kupietz | fbfcd04 | 2025-11-16 13:33:32 +0100 | [diff] [blame] | 143 | // Concatenate shebang + shaded jar into an executable launcher |
| 144 | tasks.register('assembleShebangExecutable') { |
| 145 | dependsOn shadowJar |
| 146 | inputs.file(rootProject.file("korapxmltool.shebang")) |
| Marc Kupietz | 1869f50 | 2025-11-16 21:31:12 +0100 | [diff] [blame] | 147 | inputs.file(shadowJar.archiveFile) |
| 148 | |
| 149 | def binDir = rootProject.file("build/bin") |
| 150 | def targetExec = new File(binDir, "korapxmltool") |
| 151 | outputs.file(targetExec) |
| Marc Kupietz | fbfcd04 | 2025-11-16 13:33:32 +0100 | [diff] [blame] | 152 | |
| 153 | doLast { |
| 154 | def shebang = rootProject.file("korapxmltool.shebang") |
| 155 | if (!shebang.exists()) { |
| 156 | throw new GradleException("Missing shebang stub: ${shebang}") |
| 157 | } |
| 158 | |
| Marc Kupietz | 1869f50 | 2025-11-16 21:31:12 +0100 | [diff] [blame] | 159 | // Ensure bin directory exists |
| 160 | binDir.mkdirs() |
| 161 | |
| Marc Kupietz | fbfcd04 | 2025-11-16 13:33:32 +0100 | [diff] [blame] | 162 | def targetJar = shadowJar.archiveFile.get().asFile |
| Marc Kupietz | fbfcd04 | 2025-11-16 13:33:32 +0100 | [diff] [blame] | 163 | |
| 164 | targetExec.withOutputStream { os -> |
| 165 | os << shebang.bytes |
| 166 | os << targetJar.bytes |
| 167 | } |
| Marc Kupietz | 05d3bbb | 2025-11-17 15:17:03 +0100 | [diff] [blame^] | 168 | targetExec.setExecutable(true, false) |
| Marc Kupietz | fbfcd04 | 2025-11-16 13:33:32 +0100 | [diff] [blame] | 169 | println "Created executable launcher: ${targetExec}" |
| 170 | } |
| 171 | } |
| 172 | |
| Marc Kupietz | 1869f50 | 2025-11-16 21:31:12 +0100 | [diff] [blame] | 173 | tasks.named('assemble') { |
| 174 | dependsOn createJarSymlink |
| 175 | dependsOn assembleShebangExecutable |
| 176 | } |
| 177 | |
| Marc Kupietz | f13fc7b | 2025-10-31 17:28:21 +0100 | [diff] [blame] | 178 | tasks.named('build') { |
| Marc Kupietz | 64dce82 | 2025-11-02 14:39:39 +0100 | [diff] [blame] | 179 | dependsOn createJarSymlink |
| Marc Kupietz | fbfcd04 | 2025-11-16 13:33:32 +0100 | [diff] [blame] | 180 | dependsOn assembleShebangExecutable |
| Marc Kupietz | 4f6ed42 | 2024-03-01 07:27:46 +0100 | [diff] [blame] | 181 | } |
| 182 | |
| 183 | |
| 184 | configurations { |
| 185 | runtimeLib.extendsFrom implementation |
| 186 | } |