@@ -68,10 +68,10 @@ public class JLinkImageMojo extends AbstractMojo {
6868 private boolean addClassDataSharingArchive ;
6969
7070 /**
71- * Add an AOT cache to reduce startup time.
71+ * Add an AOT cache to reduce startup time if Java 25 or newer: true, false, cds .
7272 */
73- @ Parameter (defaultValue = "true" , property = "jlink.image.addAotCache " )
74- private boolean addAotCache ;
73+ @ Parameter (defaultValue = "true" , property = "jlink.image.aotCache " )
74+ private String aotCache ;
7575
7676 /**
7777 * Test the image after creation.
@@ -178,22 +178,28 @@ private Path mainJar(Path buildDir) throws MojoFailureException {
178178 *
179179 * @return Startup cache type to use
180180 */
181- private Configuration .CacheType determinCacheType () {
181+ private Configuration .CacheType determinCacheType () throws MojoFailureException {
182+
183+ if (!addClassDataSharingArchive ) {
184+ // For backwards compatibility we don't generate any cache if old CDS flag is false
185+ // No matter what JDK we are running on.
186+ return Configuration .CacheType .NONE ;
187+ }
188+
182189 if (JavaRuntime .CURRENT_JDK .version ().feature () <= 24 ) {
183- if (addClassDataSharingArchive ) {
184- return Configuration .CacheType .CDS ;
185- } else {
186- return Configuration .CacheType .NONE ;
187- }
190+ return Configuration .CacheType .CDS ;
188191 }
189192
190193 // Java 25 or newer
191- if (addAotCache ) {
194+ if (aotCache .equalsIgnoreCase ("true" )) {
195+ // Default case under Java 25
192196 return Configuration .CacheType .AOT ;
193- } else if (addClassDataSharingArchive ) {
197+ } else if (aotCache .equalsIgnoreCase ("false" )) {
198+ return Configuration .CacheType .NONE ;
199+ } else if (aotCache .equalsIgnoreCase ("cds" )) {
194200 return Configuration .CacheType .CDS ;
195201 } else {
196- return Configuration . CacheType . NONE ;
202+ throw new MojoFailureException ( "Invalid aotCache value " + aotCache + ": must be one of: true, false, cds" ) ;
197203 }
198204 }
199205}
0 commit comments