|
| 1 | +plugins { |
| 2 | + id 'java' |
| 3 | + id 'application' |
| 4 | +} |
| 5 | + |
| 6 | +defaultTasks 'dist' |
| 7 | + |
| 8 | +java { |
| 9 | + sourceCompatibility = JavaVersion.VERSION_21 |
| 10 | + targetCompatibility = JavaVersion.VERSION_21 |
| 11 | +} |
| 12 | + |
| 13 | +// No repositories needed since we're using local JARs |
| 14 | +repositories { |
| 15 | + // Empty - using local JAR files only |
| 16 | +} |
| 17 | + |
| 18 | +dependencies { |
| 19 | + implementation files('jars/bcp47j.jar') |
| 20 | + implementation files('jars/json.jar') |
| 21 | + implementation files('jars/jsoup.jar') |
| 22 | + implementation files('jars/mapdb.jar') |
| 23 | + implementation files('jars/openxliff.jar') |
| 24 | + implementation files('jars/sqlite-jdbc-3.51.1.0.jar') |
| 25 | + implementation files('jars/swordfish.jar') |
| 26 | + implementation files('jars/xmljava.jar') |
| 27 | +} |
| 28 | + |
| 29 | +application { |
| 30 | + mainModule = 'fluenta' |
| 31 | + mainClass = 'com.maxprograms.fluenta.Fluenta' |
| 32 | +} |
| 33 | + |
| 34 | +sourceSets { |
| 35 | + main { |
| 36 | + java { |
| 37 | + srcDirs = ['src'] |
| 38 | + } |
| 39 | + resources { |
| 40 | + srcDirs = ['src'] |
| 41 | + exclude '**/*.java' |
| 42 | + exclude '**/*.xcf' |
| 43 | + } |
| 44 | + } |
| 45 | +} |
| 46 | + |
| 47 | +compileJava { |
| 48 | + outputs.upToDateWhen { false } // Always rebuild |
| 49 | + |
| 50 | + doFirst { |
| 51 | + // Create the output directory for compilation |
| 52 | + delete 'out' |
| 53 | + mkdir 'out' |
| 54 | + } |
| 55 | + |
| 56 | + options.compilerArgs = ['--module-path', configurations.compileClasspath.asPath] |
| 57 | + destinationDirectory = file('out') |
| 58 | + |
| 59 | + doLast { |
| 60 | + // Copy all resource files from src to out directory (everything except .java files) |
| 61 | + copy { |
| 62 | + from 'src' |
| 63 | + into 'out' |
| 64 | + exclude '**/*.java' |
| 65 | + exclude '**/*.xcf' |
| 66 | + } |
| 67 | + println "✓ Java compilation and resource copying completed" |
| 68 | + } |
| 69 | +} |
| 70 | + |
| 71 | +tasks.register('createJar', Jar) { |
| 72 | + dependsOn compileJava |
| 73 | + outputs.upToDateWhen { false } // Always rebuild |
| 74 | + description = 'Build fluenta.jar file' |
| 75 | + group = 'build' |
| 76 | + archiveBaseName = 'fluenta' |
| 77 | + destinationDirectory = file('jars') |
| 78 | + from 'out' |
| 79 | + |
| 80 | + doFirst { |
| 81 | + // Delete existing JAR file |
| 82 | + delete 'jars/fluenta.jar' |
| 83 | + } |
| 84 | + |
| 85 | + // Include all files from out directory except Java source files |
| 86 | + include '**/*' |
| 87 | + exclude '**/*.java' |
| 88 | + exclude '**/*.xcf' |
| 89 | + |
| 90 | + manifest { |
| 91 | + attributes( |
| 92 | + 'Automatic-Module-Name': 'fluenta', |
| 93 | + 'Module-Path': configurations.runtimeClasspath.asPath |
| 94 | + ) |
| 95 | + } |
| 96 | + |
| 97 | + doLast { |
| 98 | + println "✓ JAR created: ${archiveFile.get()}" |
| 99 | + } |
| 100 | +} |
| 101 | + |
| 102 | +tasks.register('linkJava', Exec) { |
| 103 | + dependsOn createJar |
| 104 | + outputs.upToDateWhen { false } // Always rebuild |
| 105 | + |
| 106 | + doFirst { |
| 107 | + // Clean up previous dist directory before creating new one |
| 108 | + delete 'dist' |
| 109 | + } |
| 110 | + |
| 111 | + // Cross-platform file separator handling |
| 112 | + def pathSeparator = File.pathSeparator |
| 113 | + def fileSeparator = File.separator |
| 114 | + def javaHome = System.getProperty('java.home') |
| 115 | + def jmodsPath = javaHome + fileSeparator + 'jmods' |
| 116 | + def modulePath = 'jars' + pathSeparator + jmodsPath |
| 117 | + |
| 118 | + // Use jlink command - works cross-platform |
| 119 | + commandLine 'jlink', |
| 120 | + '--module-path', modulePath, |
| 121 | + '--add-modules', 'fluenta', |
| 122 | + '--output', 'dist', |
| 123 | + '--verbose' |
| 124 | + |
| 125 | + doLast { |
| 126 | + // Clean up jrt-fs.jar if it exists |
| 127 | + def jrtFile = file('dist/lib/jrt-fs.jar') |
| 128 | + if (jrtFile.exists()) { |
| 129 | + delete jrtFile |
| 130 | + } |
| 131 | + println "✓ Runtime image created successfully" |
| 132 | + } |
| 133 | +} |
| 134 | + |
| 135 | +tasks.register('copyWindows') { |
| 136 | + dependsOn linkJava |
| 137 | + outputs.upToDateWhen { false } // Always rebuild |
| 138 | + onlyIf { System.getProperty('os.name').toLowerCase().contains('windows') } |
| 139 | + |
| 140 | + doLast { |
| 141 | + // Clean up existing directories first to avoid permission issues |
| 142 | + delete 'bin', 'conf', 'include', 'legal', 'lib' |
| 143 | + delete 'release' |
| 144 | + |
| 145 | + copy { |
| 146 | + from 'dist/bin' |
| 147 | + into 'bin' |
| 148 | + } |
| 149 | + copy { |
| 150 | + from 'dist/conf' |
| 151 | + into 'conf' |
| 152 | + } |
| 153 | + copy { |
| 154 | + from 'dist/include' |
| 155 | + into 'include' |
| 156 | + } |
| 157 | + copy { |
| 158 | + from 'dist/legal' |
| 159 | + into 'legal' |
| 160 | + } |
| 161 | + copy { |
| 162 | + from 'dist/lib' |
| 163 | + into 'lib' |
| 164 | + } |
| 165 | + copy { |
| 166 | + from 'dist/release' |
| 167 | + into '.' |
| 168 | + } |
| 169 | + delete 'dist' |
| 170 | + delete 'build' |
| 171 | + delete 'out' |
| 172 | + } |
| 173 | +} |
| 174 | + |
| 175 | +tasks.register('copyUnix') { |
| 176 | + dependsOn linkJava |
| 177 | + outputs.upToDateWhen { false } // Always rebuild |
| 178 | + onlyIf { !System.getProperty('os.name').toLowerCase().contains('windows') } |
| 179 | + |
| 180 | + doLast { |
| 181 | + // Clean up existing directories first to avoid permission issues |
| 182 | + delete 'bin', 'conf', 'include', 'legal', 'lib' |
| 183 | + delete 'release' |
| 184 | + |
| 185 | + copy { |
| 186 | + from 'dist/bin' |
| 187 | + into 'bin' |
| 188 | + } |
| 189 | + copy { |
| 190 | + from 'dist/conf' |
| 191 | + into 'conf' |
| 192 | + } |
| 193 | + copy { |
| 194 | + from 'dist/include' |
| 195 | + into 'include' |
| 196 | + } |
| 197 | + copy { |
| 198 | + from 'dist/legal' |
| 199 | + into 'legal' |
| 200 | + } |
| 201 | + copy { |
| 202 | + from 'dist/lib' |
| 203 | + into 'lib' |
| 204 | + } |
| 205 | + copy { |
| 206 | + from 'dist/release' |
| 207 | + into '.' |
| 208 | + } |
| 209 | + delete 'dist' |
| 210 | + delete 'build' |
| 211 | + delete 'out' |
| 212 | + } |
| 213 | +} |
| 214 | + |
| 215 | +tasks.register('dist') { |
| 216 | + dependsOn copyWindows, copyUnix |
| 217 | + outputs.upToDateWhen { false } // Always rebuild |
| 218 | + description = 'Prepare distribution' |
| 219 | + |
| 220 | + doFirst { |
| 221 | + println "✓ Starting distribution build..." |
| 222 | + } |
| 223 | + |
| 224 | + doLast { |
| 225 | + // Clean up JAR file after distribution is ready |
| 226 | + delete 'jars/fluenta.jar' |
| 227 | + println "✓ Distribution ready" |
| 228 | + } |
| 229 | +} |
| 230 | + |
| 231 | +tasks.register('distclean', Delete) { |
| 232 | + delete 'dist', 'bin', 'conf', 'include', 'legal', 'lib', 'release' |
| 233 | +} |
| 234 | + |
| 235 | +clean { |
| 236 | + delete 'out', 'build' |
| 237 | +} |
| 238 | + |
0 commit comments