|
| 1 | +plugins { |
| 2 | + id 'java' |
| 3 | +} |
| 4 | + |
| 5 | +defaultTasks 'dist' |
| 6 | + |
| 7 | +// Disable all caching to ensure clean builds |
| 8 | +gradle.projectsEvaluated { |
| 9 | + tasks.withType(JavaCompile) { |
| 10 | + options.incremental = false |
| 11 | + outputs.upToDateWhen { false } |
| 12 | + } |
| 13 | +} |
| 14 | + |
| 15 | +// Disable caching globally |
| 16 | +gradle.taskGraph.whenReady { taskGraph -> |
| 17 | + taskGraph.allTasks.each { task -> |
| 18 | + task.outputs.upToDateWhen { false } |
| 19 | + } |
| 20 | +} |
| 21 | + |
| 22 | +java { |
| 23 | + toolchain { |
| 24 | + languageVersion = JavaLanguageVersion.of(21) |
| 25 | + } |
| 26 | + modularity.inferModulePath = true |
| 27 | +} |
| 28 | + |
| 29 | +// Source sets configuration |
| 30 | +sourceSets { |
| 31 | + main { |
| 32 | + java { |
| 33 | + srcDirs = ['src'] |
| 34 | + } |
| 35 | + resources { |
| 36 | + srcDirs = ['src'] |
| 37 | + exclude '**/*.java' |
| 38 | + } |
| 39 | + } |
| 40 | +} |
| 41 | + |
| 42 | +tasks.withType(JavaCompile).configureEach { |
| 43 | + options.release = 21 |
| 44 | + options.encoding = 'UTF-8' |
| 45 | +} |
| 46 | + |
| 47 | + |
| 48 | +dependencies { |
| 49 | + implementation files('lib/bcp47j.jar') |
| 50 | + implementation files('lib/json.jar') |
| 51 | + implementation files('lib/jsoup.jar') |
| 52 | + implementation files('lib/mapdb.jar') |
| 53 | + implementation files('lib/xmljava.jar') |
| 54 | + implementation files('lib/openxliff.jar') |
| 55 | +} |
| 56 | + |
| 57 | +// Configure JAR task |
| 58 | +jar { |
| 59 | + archiveFileName = 'javapm.jar' |
| 60 | + destinationDirectory = file('lib') |
| 61 | + duplicatesStrategy = DuplicatesStrategy.EXCLUDE |
| 62 | + |
| 63 | + // Disable caching for JAR task |
| 64 | + outputs.upToDateWhen { false } |
| 65 | +} |
| 66 | + |
| 67 | +// Task to create jlink image |
| 68 | +task jlinkImage(type: Exec) { |
| 69 | + description = 'Create modular runtime image with jlink' |
| 70 | + group = 'distribution' |
| 71 | + dependsOn jar |
| 72 | + |
| 73 | + // Disable caching for jlink task |
| 74 | + outputs.upToDateWhen { false } |
| 75 | + |
| 76 | + doFirst { |
| 77 | + // Only clean dist directory before jlink |
| 78 | + delete 'dist' |
| 79 | + } |
| 80 | + |
| 81 | + def modulePath = "lib${File.pathSeparator}${System.getProperty('java.home')}${File.separator}jmods" |
| 82 | + |
| 83 | + commandLine 'jlink', |
| 84 | + '--module-path', modulePath, |
| 85 | + '--add-modules', 'javapm', |
| 86 | + '--output', 'dist', |
| 87 | + '--no-man-pages', |
| 88 | + '--no-header-files' |
| 89 | + |
| 90 | + doLast { |
| 91 | + // Remove javapm.jar and jrt-fs.jar |
| 92 | + delete 'lib/javapm.jar' |
| 93 | + delete 'dist/lib/jrt-fs.jar' |
| 94 | + } |
| 95 | +} |
| 96 | + |
| 97 | +// Task to copy batch files (Windows) |
| 98 | +task copyBats { |
| 99 | + description = 'Copy .cmd files to /dist' |
| 100 | + group = 'distribution' |
| 101 | + |
| 102 | + doLast { |
| 103 | + if (System.getProperty('os.name').toLowerCase().contains('windows')) { |
| 104 | + copy { |
| 105 | + from fileTree('.') { include '*.cmd' } |
| 106 | + into 'dist' |
| 107 | + } |
| 108 | + } |
| 109 | + } |
| 110 | +} |
| 111 | + |
| 112 | +// Task to copy shell scripts (Unix/Linux/macOS) |
| 113 | +task copyShells { |
| 114 | + description = 'Copy .sh files to /dist' |
| 115 | + group = 'distribution' |
| 116 | + |
| 117 | + doLast { |
| 118 | + if (!System.getProperty('os.name').toLowerCase().contains('windows')) { |
| 119 | + copy { |
| 120 | + from fileTree('.') { include '*.sh' } |
| 121 | + into 'dist' |
| 122 | + } |
| 123 | + |
| 124 | + // Make shell scripts executable |
| 125 | + fileTree('dist').matching { include '**/*.sh' }.each { file -> |
| 126 | + file.setExecutable(true, false) |
| 127 | + } |
| 128 | + } |
| 129 | + } |
| 130 | +} |
| 131 | + |
| 132 | +// Task to copy additional resources |
| 133 | +task copyResources { |
| 134 | + description = 'Copy additional resources to /dist/' |
| 135 | + group = 'distribution' |
| 136 | + |
| 137 | + doLast { |
| 138 | + copy { |
| 139 | + from 'catalog' |
| 140 | + into 'dist/catalog' |
| 141 | + } |
| 142 | + |
| 143 | + copy { |
| 144 | + from 'srx' |
| 145 | + into 'dist/srx' |
| 146 | + } |
| 147 | + |
| 148 | + copy { |
| 149 | + from 'LICENSE' |
| 150 | + into 'dist' |
| 151 | + } |
| 152 | + } |
| 153 | +} |
| 154 | + |
| 155 | +// Main distribution task |
| 156 | +task dist { |
| 157 | + description = 'Prepare distribution' |
| 158 | + group = 'distribution' |
| 159 | + |
| 160 | + dependsOn clean, jlinkImage, copyBats, copyShells, copyResources |
| 161 | + |
| 162 | + // Ensure clean runs first, then jlink, then copy tasks |
| 163 | + jlinkImage.mustRunAfter clean |
| 164 | + copyBats.mustRunAfter jlinkImage |
| 165 | + copyShells.mustRunAfter jlinkImage |
| 166 | + copyResources.mustRunAfter jlinkImage |
| 167 | +} |
| 168 | + |
| 169 | +// Task to clean up build artifacts after distribution |
| 170 | +task cleanupAfterDist { |
| 171 | + description = 'Clean up build artifacts after distribution is complete' |
| 172 | + group = 'build' |
| 173 | + |
| 174 | + doLast { |
| 175 | + delete 'build' |
| 176 | + // Remove empty bin directory if it exists |
| 177 | + if (file('bin').exists() && file('bin').list().length == 0) { |
| 178 | + file('bin').deleteDir() |
| 179 | + } |
| 180 | + } |
| 181 | +} |
| 182 | + |
| 183 | +// Make cleanup run after dist |
| 184 | +dist.finalizedBy cleanupAfterDist |
| 185 | + |
| 186 | +// Clean task to remove dist directory |
| 187 | +task distclean { |
| 188 | + description = 'Remove dist directory' |
| 189 | + group = 'distribution' |
| 190 | + |
| 191 | + doLast { |
| 192 | + delete 'dist' |
| 193 | + } |
| 194 | +} |
| 195 | + |
| 196 | +// Configure clean task to remove all build artifacts |
| 197 | +clean { |
| 198 | + delete 'lib/javapm.jar' |
| 199 | + delete 'bin' |
| 200 | + delete 'dist' |
| 201 | + delete 'build' |
| 202 | + |
| 203 | + doLast { |
| 204 | + // Ensure bin directory is completely removed |
| 205 | + file('bin').deleteDir() |
| 206 | + } |
| 207 | +} |
| 208 | + |
| 209 | +// Configure compiler options for clean builds |
| 210 | +compileJava { |
| 211 | + options.encoding = 'UTF-8' |
| 212 | + options.incremental = false |
| 213 | + options.fork = true |
| 214 | + options.compilerArgs += [ |
| 215 | + '--module-path', classpath.asPath |
| 216 | + ] |
| 217 | + |
| 218 | + // Disable caching for compilation |
| 219 | + outputs.upToDateWhen { false } |
| 220 | + |
| 221 | + // Always clean destination before compilation |
| 222 | + doFirst { |
| 223 | + delete destinationDirectory |
| 224 | + } |
| 225 | +} |
0 commit comments