forked from rmraya/OpenXLIFF
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.gradle
More file actions
271 lines (227 loc) · 6.26 KB
/
build.gradle
File metadata and controls
271 lines (227 loc) · 6.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
plugins {
id 'java'
}
// Disable all caching to ensure clean builds
gradle.projectsEvaluated {
tasks.withType(JavaCompile) {
options.incremental = false
outputs.upToDateWhen { false }
}
}
// Disable caching globally
gradle.taskGraph.whenReady { taskGraph ->
taskGraph.allTasks.each { task ->
task.outputs.upToDateWhen { false }
}
}
// Set Java version
java {
sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21
modularity.inferModulePath = true
}
// Source sets configuration
sourceSets {
main {
java {
srcDirs = ['src']
}
resources {
srcDirs = ['src']
exclude '**/*.java'
}
}
}
// Use existing JAR files from lib folder
dependencies {
implementation files('lib/bcp47j.jar')
implementation files('lib/json.jar')
implementation files('lib/jsoup.jar')
implementation files('lib/xmljava.jar')
}
// Task to clean up build artifacts after compilation
task cleanupBuildDir {
description = 'Clean up build directory after tasks complete'
group = 'build'
doLast {
delete 'build'
}
}
// Configure JAR task
jar {
archiveFileName = 'openxliff.jar'
destinationDirectory = file('lib')
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
// Disable caching for JAR task
outputs.upToDateWhen { false }
// Clean up build directory after JAR is created
finalizedBy cleanupBuildDir
}
// Task to create jlink image
task jlinkImage(type: Exec) {
description = 'Create modular runtime image with jlink'
group = 'distribution'
dependsOn jar
// Disable caching for jlink task
outputs.upToDateWhen { false }
doFirst {
// Only clean dist directory before jlink
delete 'dist'
}
def modulePath = "lib${File.pathSeparator}${System.getProperty('java.home')}${File.separator}jmods"
commandLine 'jlink',
'--module-path', modulePath,
'--add-modules', 'openxliff',
'--output', 'dist',
'--no-man-pages',
'--no-header-files'
doLast {
// Remove jrt-fs.jar
delete file('dist/lib/jrt-fs.jar')
}
}
// Task to copy batch files (Windows)
task copyBats {
description = 'Copy .cmd files to /dist'
group = 'distribution'
doLast {
if (System.getProperty('os.name').toLowerCase().contains('windows')) {
copy {
from projectDir
into 'dist'
include '*.cmd'
}
}
}
}
// Task to copy shell scripts (Unix/Linux/macOS)
task copyShells {
description = 'Copy .sh files to /dist'
group = 'distribution'
doLast {
if (!System.getProperty('os.name').toLowerCase().contains('windows')) {
copy {
from projectDir
into 'dist'
include '*.sh'
}
// Make all shell scripts executable with proper permissions
fileTree('dist').matching { include '**/*.sh' }.each { file ->
file.setExecutable(true, false) // executable for owner and group
file.setReadable(true, false) // readable for owner and group
}
}
}
}
// Task to copy licenses
task copyLicenses {
description = 'Copy license info to /dist/'
group = 'distribution'
doLast {
copy {
from 'licenses'
into 'dist/licenses'
}
}
}
// Task to copy additional resources
task copyResources {
description = 'Copy additional resources to /dist/'
group = 'distribution'
doLast {
copy {
from 'catalog'
into 'dist/catalog'
}
copy {
from 'srx'
into 'dist/srx'
}
copy {
from 'xmlfilter'
into 'dist/xmlfilter'
}
copy {
from 'LICENSE'
into 'dist'
}
}
}
// Main distribution task
task dist {
description = 'Prepare distribution'
group = 'distribution'
dependsOn jlinkImage, copyBats, copyShells, copyLicenses, copyResources
// Ensure jlink runs before other copy tasks
copyBats.mustRunAfter jlinkImage
copyShells.mustRunAfter jlinkImage
copyLicenses.mustRunAfter jlinkImage
copyResources.mustRunAfter jlinkImage
// Clean up build artifacts after distribution is complete
doLast {
delete 'build'
// Remove empty bin directory if it exists
if (file('bin').exists() && file('bin').list().length == 0) {
file('bin').deleteDir()
}
}
}
// Clean task to remove dist directory
task distclean {
description = 'Remove dist directory'
group = 'distribution'
doLast {
delete 'dist'
}
}
// Make dist the default task
defaultTasks 'dist'
// Configure clean task to remove all build artifacts
clean {
delete 'lib/openxliff.jar'
delete 'bin'
delete 'dist'
delete 'build'
doLast {
// Ensure bin directory is completely removed
file('bin').deleteDir()
}
}
// Task to force clean everything before compilation
task forceClean {
description = 'Force clean all build artifacts and caches'
group = 'build'
doLast {
delete 'lib/openxliff.jar'
delete 'bin'
delete 'dist'
delete 'build'
// Clear any cached class files in source directories
delete fileTree('src') { include '**/*.class' }
}
}
// Ensure proper build order with clean compilation
compileJava.dependsOn clean
jar.dependsOn compileJava
jlinkImage.dependsOn jar
// Configure compiler options for clean builds
compileJava {
options.encoding = 'UTF-8'
options.incremental = false
options.fork = true
options.compilerArgs += [
'--module-path', classpath.asPath
]
// Disable caching for compilation
outputs.upToDateWhen { false }
// Always clean destination before compilation
doFirst {
delete destinationDirectory
}
// Clean up empty bin directory after compilation if needed
doLast {
if (file('bin').exists() && file('bin').list().length == 0) {
file('bin').deleteDir()
}
}
}