@@ -17,24 +17,20 @@ publishing {
1717 }
1818}
1919
20- // ----------------------- Tool discovery (jdeps/jlink via toolchain) -----------------
20+
21+ def toolJavaHome = {
22+ def svc = project. extensions. getByType(JavaToolchainService )
23+ def launcher = svc. launcherFor(project. java. toolchain)
24+ launcher. get(). metadata. installationPath. asFile
25+ }
26+
2127def toolExecutable = { String toolName ->
22- File javaHome = null
23- def envHome = System . getenv(' JAVA_HOME' )
24- if (envHome) {
25- javaHome = new File (envHome)
26- }
27- if (! javaHome?. exists()) {
28- def svc = project. extensions. getByType(JavaToolchainService )
29- def launcher = svc. launcherFor(project. java. toolchain)
30- javaHome = launcher. get(). metadata. installationPath. asFile
31- }
28+ def javaHome = System . getenv(' JAVA_HOME' ) ? new File (System . getenv(' JAVA_HOME' )) : toolJavaHome()
3229 def ext = OperatingSystem . current(). isWindows() ? " .exe" : " "
33- def path = new File (javaHome, " bin/${ toolName}${ ext} " ). absolutePath
34- logger. lifecycle(" [tools] Using ${ toolName} at ${ path} " )
35- return path
30+ new File (javaHome, " bin/${ toolName}${ ext} " ). absolutePath
3631}
3732
33+
3834// ----------------------- Common providers/locations ---------------------------------
3935def fatJar = tasks. named(' shadowJar' ). flatMap { it. archiveFile }
4036
@@ -90,6 +86,7 @@ tasks.register("jdepsModules") {
9086 }
9187}
9288
89+ // 2) Build slim runtime with jlink (overwrite if exists)
9390// 2) Build slim runtime with jlink (overwrite if exists)
9491tasks. register(" jlinkRuntime25" ) {
9592 description = " Builds a slim Java 25 runtime image containing only the needed modules"
@@ -101,28 +98,42 @@ tasks.register("jlinkRuntime25") {
10198
10299 doLast {
103100 ExecOperations execOps = project. services. get(ExecOperations )
104- def jlink = toolExecutable(" jlink" )
105- def mods = modulesTxt. get(). asFile. text. trim()
106- def outDir = jreImageDir. get(). asFile
101+
102+ // Resolve Java home from toolchain (fallback to JAVA_HOME if set)
103+ def svc = project. extensions. getByType(JavaToolchainService )
104+ def launcher = svc. launcherFor(project. java. toolchain)
105+ File javaHome = System . getenv(' JAVA_HOME' ) ? new File (System . getenv(' JAVA_HOME' )) : launcher. get(). metadata. installationPath. asFile
106+
107+ def jlink = new File (javaHome, " bin/${ OperatingSystem.current().isWindows() ? 'jlink.exe' : 'jlink'} " ). absolutePath
108+ def jmodsDir = new File (javaHome, " jmods" ). absolutePath
109+ def mods = modulesTxt. get(). asFile. text. trim()
110+ def outDir = jreImageDir. get(). asFile
107111
108112 if (! mods) throw new GradleException (" No modules detected for jlink." )
113+
109114 // jlink requires the output dir to NOT exist
110- if (outDir. exists()) project. delete(outDir)
115+ if (outDir. exists()) {
116+ project. delete(outDir)
117+ }
111118 outDir. parentFile. mkdirs()
112119
113120 logger. lifecycle(" [jlink] Using: ${ jlink} " )
121+ logger. lifecycle(" [jlink] JAVA_HOME: ${ javaHome} " )
122+ logger. lifecycle(" [jlink] jmods: ${ jmodsDir} " )
114123 logger. lifecycle(" [jlink] Modules: ${ mods} " )
115124
116125 def errBuf = new ByteArrayOutputStream ()
117126 def outBuf = new ByteArrayOutputStream ()
127+
118128 def result = execOps. exec {
119129 commandLine jlink,
120130 " --verbose" ,
131+ " --module-path" , jmodsDir, // <— force clean jmods
121132 " --add-modules" , mods,
122133 " --no-header-files" ,
123134 " --no-man-pages" ,
124135 " --strip-debug" ,
125- " --compress" , " zip-6" ,
136+ " --compress" , " zip-6" , // replaces deprecated "--compress=2"
126137 " --output" , outDir. absolutePath
127138 errorOutput = errBuf
128139 standardOutput = outBuf
@@ -140,6 +151,7 @@ tasks.register("jlinkRuntime25") {
140151}
141152
142153
154+
143155// 3) Assemble folder layout: jre + compiler.jar (no manifest)
144156tasks. register(" assembleSlimCompilerDist" , Copy ) {
145157 description = " Assembles dist folder with slim JRE and compiler.jar (no manifest)."
0 commit comments