4545import org .graalvm .buildtools .gradle .tasks .CreateLayerOptions ;
4646import org .graalvm .buildtools .gradle .tasks .LayerOptions ;
4747import org .graalvm .buildtools .gradle .tasks .UseLayerOptions ;
48+ import org .graalvm .buildtools .model .resources .NativeImageFlags ;
4849import org .graalvm .buildtools .utils .NativeImageUtils ;
4950import org .gradle .api .Transformer ;
5051import org .gradle .api .file .ConfigurableFileCollection ;
@@ -129,7 +130,7 @@ public List<String> asArguments() {
129130 ConfigurableFileCollection jarsClasspath = null ;
130131 if (hasLayers ) {
131132 LOGGER .warn ("Experimental support for layered images enabled. DSL may change at any time." );
132- cliArgs .add ("-H:+UnlockExperimentalVMOptions" );
133+ cliArgs .add (NativeImageFlags . UNLOCK_EXPERIMENTAL_VMOPTIONS );
133134 var layers = options .getLayers ();
134135 var arg = new StringBuilder ();
135136 for (LayerOptions layer : layers ) {
@@ -139,14 +140,13 @@ public List<String> asArguments() {
139140 if (layer instanceof CreateLayerOptions ) {
140141 var create = (CreateLayerOptions ) layer ;
141142 layerCreateName = layer .getLayerName ().get ();
142- arg .append ("-H:LayerCreate =" );
143+ arg .append (NativeImageFlags . LAYER_CREATE + " =" );
143144 arg .append (layerCreateName ).append (".nil" );
144145 var modules = create .getModules ().get ();
145146 jarsClasspath = create .getJars ();
146147 boolean hasModules = !modules .isEmpty ();
147148 boolean hasPackage = create .getPackages ().isPresent () && !create .getPackages ().get ().isEmpty ();
148- var createLayerJars = jarsClasspath .getFiles ();
149- boolean hasJars = !createLayerJars .isEmpty ();
149+ boolean hasJars = !jarsClasspath .getFiles ().isEmpty ();
150150 if (hasModules || hasPackage || hasJars ) {
151151 var packages = create .getPackages ().get ();
152152 arg .append ("," );
@@ -168,7 +168,7 @@ public List<String> asArguments() {
168168 }
169169 } else {
170170 var layerUse = (UseLayerOptions ) layer ;
171- arg .append ("-H:LayerUse =" );
171+ arg .append (NativeImageFlags . LAYER_USE + " =" );
172172 arg .append (layerUse .getLayerFile ().getAsFile ().get ().getAbsolutePath ());
173173 }
174174 }
@@ -187,14 +187,14 @@ public List<String> asArguments() {
187187 cliArgs .add (jarsClasspath .getAsPath ());
188188 }
189189 appendBooleanOption (cliArgs , options .getDebug (), "-g" );
190- appendBooleanOption (cliArgs , options .getFallback ().map (NEGATE ), "--no-fallback" );
191- appendBooleanOption (cliArgs , options .getVerbose (), "--verbose" );
192- appendBooleanOption (cliArgs , options .getSharedLibrary (), "--shared" );
193- appendBooleanOption (cliArgs , options .getQuickBuild (), "-Ob" );
190+ appendBooleanOption (cliArgs , options .getFallback ().map (NEGATE ), NativeImageFlags . NO_FALLBACK );
191+ appendBooleanOption (cliArgs , options .getVerbose (), NativeImageFlags . VERBOSE );
192+ appendBooleanOption (cliArgs , options .getSharedLibrary (), NativeImageFlags . SHARED );
193+ appendBooleanOption (cliArgs , options .getQuickBuild (), NativeImageFlags . QUICK_BUILD );
194194 if (useColors .get ()) {
195- appendBooleanOption (cliArgs , options .getRichOutput (), majorJDKVersion .getOrElse (-1 ) >= 21 ? "--color" : "-H:+BuildOutputColorful" );
195+ appendBooleanOption (cliArgs , options .getRichOutput (), majorJDKVersion .getOrElse (-1 ) >= 21 ? NativeImageFlags . COLOR : NativeImageFlags . BUILD_OUTPUT_COLORFUL );
196196 }
197- appendBooleanOption (cliArgs , options .getPgoInstrument (), "--pgo-instrument" );
197+ appendBooleanOption (cliArgs , options .getPgoInstrument (), NativeImageFlags . PGO_INSTRUMENT );
198198
199199 String targetOutputPath = getExecutableName ().get ();
200200 if (layerCreateName != null ) {
@@ -221,7 +221,7 @@ public List<String> asArguments() {
221221 .map (File ::getAbsolutePath )
222222 .collect (Collectors .joining ("," ));
223223 if (!configFiles .isEmpty ()) {
224- cliArgs .add ("-H:ConfigurationFileDirectories =" + configFiles );
224+ cliArgs .add (NativeImageFlags . CONFIGURATION_FILE_DIRECTORIES + " =" + configFiles );
225225 }
226226 if (Boolean .FALSE .equals (options .getPgoInstrument ().get ()) && options .getPgoProfilesDirectory ().isPresent ()) {
227227 FileTree files = options .getPgoProfilesDirectory ().get ().getAsFileTree ();
0 commit comments