Skip to content

Commit 6545534

Browse files
committed
Migrated to gradle 9.0
1 parent 3c31806 commit 6545534

15 files changed

Lines changed: 515 additions & 83 deletions

.classpath

Lines changed: 0 additions & 40 deletions
This file was deleted.

.gitignore

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
.DS_Store
2-
/.vscode/
3-
/bin/
2+
.vscode/
3+
bin/
44
lib/javapm.jar
5-
/dist/
5+
dist/
6+
build/
7+
.gradle/

.project

Lines changed: 0 additions & 28 deletions
This file was deleted.

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ You can download compressed binary packages for Windows, macOS and Linux from [h
1616

1717
## Convert .properties to XLIFF
1818

19-
Running `.\createxliff.bat` or `./createxliff.sh` without parameters displays help for XLIFF generation.
19+
Running `.\createxliff.cmd` or `./createxliff.sh` without parameters displays help for XLIFF generation.
2020

2121
```text
2222
Usage:
2323
24-
createxliff.bat [-help] -src sourceFolder -xliff xliffFile -srcLang sourceLanguage [-tgtLang targetLanguage] [-reuse] [-2.0]
24+
createxliff.cmd [-help] -src sourceFolder -xliff xliffFile -srcLang sourceLanguage [-tgtLang targetLanguage] [-reuse] [-2.0]
2525
2626
Where:
2727
@@ -37,7 +37,7 @@ Where:
3737

3838
## Import translated XLIFF
3939

40-
Running `.\mergexliff.bat` or `./mergexliff.sh` without parameters displays help for importing translated XLIFF files.
40+
Running `.\mergexliff.cmd` or `./mergexliff.sh` without parameters displays help for importing translated XLIFF files.
4141

4242
```text
4343
Usage:
@@ -55,23 +55,23 @@ Where:
5555

5656
## Build Requirements
5757

58-
- JDK 17 or newer is required for compiling and building.
59-
- Apache Ant 1.10.12 or newer.
58+
- JDK 21 is required for compiling and building. Get it from [https://adoptium.net/](https://adoptium.net/).
59+
- Gradle 9.0. Get it from [https://gradle.org/install/](https://gradle.org/install/).
6060

6161
Pre-built binaries already include everything you need to run all options.
6262

6363
## Building
6464

6565
- Checkout this repository.
66-
- Point your JAVA_HOME variable to JDK 17
67-
- Run `ant` to generate a binary distribution in `./dist`
66+
- Point your JAVA_HOME variable to JDK 21
67+
- Run `gradle` to generate a binary distribution in `./dist`
6868

6969
### Steps for building
7070

7171
``` bash
7272
git clone https://github.com/rmraya/JavaPM.git
7373
cd JavaPM
74-
ant
74+
gradle
7575
```
7676

7777
A binary distribution will be created in `/dist` folder.

build.gradle

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

build.xml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<property name="source" value="17" />
55
<property name="build.compiler" value="javac10+" />
66
<path id="JavaPM.classpath">
7-
<pathelement location="lib/dtd.jar" />
7+
<pathelement location="lib/bcp47j.jar" />
88
<pathelement location="lib/json.jar" />
99
<pathelement location="lib/jsoup.jar" />
1010
<pathelement location="lib/mapdb.jar" />
@@ -40,12 +40,13 @@
4040
<link destDir="dist" modulepath="lib:${java.home}/jmods">
4141
<module name="javapm" />
4242
</link>
43+
<delete file="lib/javapm.jar" />
4344
<delete file="dist/lib/jrt-fs.jar" />
4445
</target>
4546
<target name="copyBats" if="isWindows">
46-
<description>Copy .bat to /dist</description>
47-
<copy file="createxliff.bat" todir="dist" />
48-
<copy file="mergexliff.bat" todir="dist" />
47+
<description>Copy .cmd to /dist</description>
48+
<copy file="createxliff.cmd" todir="dist" />
49+
<copy file="mergexliff.cmd" todir="dist" />
4950
</target>
5051
<target name="copyShells" unless="isWindows">
5152
<description>Copy .sh to /dist</description>

0 commit comments

Comments
 (0)