-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathbuild.gradle
More file actions
225 lines (187 loc) · 5.05 KB
/
build.gradle
File metadata and controls
225 lines (187 loc) · 5.05 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
plugins {
id 'java'
}
defaultTasks 'dist'
// 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 }
}
}
java {
toolchain {
languageVersion = JavaLanguageVersion.of(21)
}
modularity.inferModulePath = true
}
// Source sets configuration
sourceSets {
main {
java {
srcDirs = ['src']
}
resources {
srcDirs = ['src']
exclude '**/*.java'
}
}
}
tasks.withType(JavaCompile).configureEach {
options.release = 21
options.encoding = 'UTF-8'
}
dependencies {
implementation files('lib/bcp47j.jar')
implementation files('lib/json.jar')
implementation files('lib/jsoup.jar')
implementation files('lib/mapdb.jar')
implementation files('lib/xmljava.jar')
implementation files('lib/openxliff.jar')
}
// Configure JAR task
jar {
archiveFileName = 'javapm.jar'
destinationDirectory = file('lib')
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
// Disable caching for JAR task
outputs.upToDateWhen { false }
}
// 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', 'javapm',
'--output', 'dist',
'--no-man-pages',
'--no-header-files'
doLast {
// Remove javapm.jar and jrt-fs.jar
delete 'lib/javapm.jar'
delete '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 fileTree('.') { include '*.cmd' }
into 'dist'
}
}
}
}
// 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 fileTree('.') { include '*.sh' }
into 'dist'
}
// Make shell scripts executable
fileTree('dist').matching { include '**/*.sh' }.each { file ->
file.setExecutable(true, false)
}
}
}
}
// 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 'LICENSE'
into 'dist'
}
}
}
// Main distribution task
task dist {
description = 'Prepare distribution'
group = 'distribution'
dependsOn clean, jlinkImage, copyBats, copyShells, copyResources
// Ensure clean runs first, then jlink, then copy tasks
jlinkImage.mustRunAfter clean
copyBats.mustRunAfter jlinkImage
copyShells.mustRunAfter jlinkImage
copyResources.mustRunAfter jlinkImage
}
// Task to clean up build artifacts after distribution
task cleanupAfterDist {
description = 'Clean up build artifacts after distribution is complete'
group = 'build'
doLast {
delete 'build'
// Remove empty bin directory if it exists
if (file('bin').exists() && file('bin').list().length == 0) {
file('bin').deleteDir()
}
}
}
// Make cleanup run after dist
dist.finalizedBy cleanupAfterDist
// Clean task to remove dist directory
task distclean {
description = 'Remove dist directory'
group = 'distribution'
doLast {
delete 'dist'
}
}
// Configure clean task to remove all build artifacts
clean {
delete 'lib/javapm.jar'
delete 'bin'
delete 'dist'
delete 'build'
doLast {
// Ensure bin directory is completely removed
file('bin').deleteDir()
}
}
// 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
}
}