-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathbuild.gradle
More file actions
234 lines (202 loc) · 5.41 KB
/
build.gradle
File metadata and controls
234 lines (202 loc) · 5.41 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
plugins {
id 'java'
id 'application'
}
defaultTasks 'dist'
java {
toolchain {
languageVersion = JavaLanguageVersion.of(21)
}
}
// No repositories needed since we're using local JARs
repositories {
// Empty - using local JAR files only
}
dependencies {
implementation files('jars/bcp47j.jar')
implementation files('jars/json.jar')
implementation files('jars/jsoup.jar')
implementation files('jars/mapdb.jar')
implementation files('jars/openxliff.jar')
implementation files('jars/xmljava.jar')
implementation files('jars/sqlite-jdbc-3.51.1.0.jar')
}
application {
mainModule = 'swordfish'
}
sourceSets {
main {
java {
srcDirs = ['src']
}
resources {
srcDirs = ['src']
exclude '**/*.java'
}
}
}
compileJava {
outputs.upToDateWhen { false } // Always rebuild
doFirst {
// Create the output directory for compilation
delete 'out'
mkdir 'out'
}
options.compilerArgs = ['--module-path', configurations.compileClasspath.asPath]
destinationDirectory = file('out')
doLast {
// Copy all resource files from src to out directory (everything except .java files)
copy {
from 'src'
into 'out'
exclude '**/*.java'
}
println "✓ Java compilation and resource copying completed"
}
}
tasks.register('createJar', Jar) {
dependsOn compileJava
outputs.upToDateWhen { false } // Always rebuild
description = 'Build swordfish.jar file'
group = 'build'
archiveBaseName = 'swordfish'
destinationDirectory = file('jars')
from 'out'
doFirst {
// Delete existing JAR file
delete 'jars/swordfish.jar'
}
// Include all files from out directory except Java source files
include '**/*'
exclude '**/*.java'
manifest {
attributes(
'Automatic-Module-Name': 'swordfish',
'Module-Path': configurations.runtimeClasspath.asPath
)
}
doLast {
println "✓ JAR created: ${archiveFile.get()}"
}
}
tasks.register('linkJava', Exec) {
dependsOn createJar
outputs.upToDateWhen { false } // Always rebuild
doFirst {
// Clean up previous dist directory before creating new one
delete 'dist'
}
// Cross-platform file separator handling
def pathSeparator = File.pathSeparator
def fileSeparator = File.separator
def javaHome = System.getProperty('java.home')
def jmodsPath = javaHome + fileSeparator + 'jmods'
def modulePath = 'jars' + pathSeparator + jmodsPath
// Use jlink command - works cross-platform
commandLine 'jlink',
'--module-path', modulePath,
'--add-modules', 'swordfish',
'--output', 'dist',
'--verbose'
doLast {
// Clean up jrt-fs.jar if it exists
def jrtFile = file('dist/lib/jrt-fs.jar')
if (jrtFile.exists()) {
delete jrtFile
}
println "✓ Runtime image created successfully"
}
}
tasks.register('copyWindows') {
dependsOn linkJava
outputs.upToDateWhen { false } // Always rebuild
onlyIf { System.getProperty('os.name').toLowerCase().contains('windows') }
doLast {
// Clean up existing directories first to avoid permission issues
delete 'bin', 'conf', 'include', 'legal', 'lib'
delete 'release'
copy {
from 'dist/bin'
into 'bin'
}
copy {
from 'dist/conf'
into 'conf'
}
copy {
from 'dist/include'
into 'include'
}
copy {
from 'dist/legal'
into 'legal'
}
copy {
from 'dist/lib'
into 'lib'
}
copy {
from 'dist/release'
into '.'
}
delete 'dist'
delete 'build'
delete 'out'
}
}
tasks.register('copyUnix') {
dependsOn linkJava
outputs.upToDateWhen { false } // Always rebuild
onlyIf { !System.getProperty('os.name').toLowerCase().contains('windows') }
doLast {
// Clean up existing directories first to avoid permission issues
delete 'bin', 'conf', 'include', 'legal', 'lib'
delete 'release'
copy {
from 'dist/bin'
into 'bin'
}
copy {
from 'dist/conf'
into 'conf'
}
copy {
from 'dist/include'
into 'include'
}
copy {
from 'dist/legal'
into 'legal'
}
copy {
from 'dist/lib'
into 'lib'
}
copy {
from 'dist/release'
into '.'
}
delete 'dist'
delete 'build'
delete 'out'
}
}
tasks.register('dist') {
dependsOn copyWindows, copyUnix
outputs.upToDateWhen { false } // Always rebuild
description = 'Prepare distribution'
doFirst {
println "✓ Starting distribution build..."
}
doLast {
// Clean up JAR file after distribution is ready
delete 'jars/swordfish.jar'
println "✓ Distribution ready"
}
}
tasks.register('distclean', Delete) {
delete 'dist', 'bin', 'conf', 'include', 'legal', 'lib', 'release'
}
clean {
delete 'out', 'build'
}