@@ -91,29 +91,29 @@ public static File findNativeImageExecutable(Property<JavaLauncher> javaLauncher
9191 executablePath = metadata .getInstallationPath ().file ("bin/" + NATIVE_IMAGE_EXE ).getAsFile ();
9292 }
9393
94- try {
95- if (!executablePath .exists ()) {
96- logger .log ("Native Image executable wasn't found. We will now try to download it. " );
97- File graalVmHomeGuess = executablePath .getParentFile ();
98-
99- File guPath = graalVmHomeGuess .toPath ().resolve (GU_EXE ).toFile ();
100- if (!guPath .exists ()) {
101- throw new GradleException ("'" + GU_EXE + "' at '" + guPath + "' tool wasn't found. This probably means that JDK at isn't a GraalVM distribution." );
102- }
103- ExecResult res = execOperations .exec (spec -> {
104- spec .args ("install" , "native-image" );
105- spec .setExecutable (Paths .get (graalVmHomeGuess .getAbsolutePath (), GU_EXE ));
106- });
107- if (res .getExitValue () != 0 ) {
108- throw new GradleException ("Native Image executable wasn't found, and '" + GU_EXE + "' tool failed to install it." );
109- }
110- diagnostics .withGuInstall ();
94+ File graalVmHomeGuess = executablePath .getParentFile ();
95+ File guPath = graalVmHomeGuess .toPath ().resolve (GU_EXE ).toFile ();
96+ if (guPath .exists () && !executablePath .exists ()) {
97+ logger .log ("Native Image executable wasn't found. We will now try to download it. " );
98+
99+ ExecResult res = execOperations .exec (spec -> {
100+ spec .args ("install" , "native-image" );
101+ spec .setExecutable (Paths .get (graalVmHomeGuess .getAbsolutePath (), GU_EXE ));
102+ });
103+ if (res .getExitValue () != 0 ) {
104+ throw new GradleException ("Native Image executable wasn't found, and '" + GU_EXE + "' tool failed to install it.\n " +
105+ "Make sure to declare the GRAALVM_HOME or JAVA_HOME environment variable or install GraalVM with " +
106+ "native-image in a standard location recognized by Gradle Java toolchain support" );
111107 }
112- } catch (GradleException e ) {
113- throw new GradleException ("Determining GraalVM installation failed with message: " + e .getMessage () + "\n \n "
114- + "Make sure to declare the GRAALVM_HOME environment variable or install GraalVM with " +
115- "native-image in a standard location recognized by Gradle Java toolchain support" );
108+ diagnostics .withGuInstall ();
116109 }
110+
111+ if (!executablePath .exists ()) {
112+ throw new GradleException (executablePath + " wasn't found. This probably means that JDK isn't a GraalVM distribution.\n " +
113+ "Make sure to declare the GRAALVM_HOME or JAVA_HOME environment variable or install GraalVM with" +
114+ "native-image in a standard location recognized by Gradle Java toolchain support" );
115+ }
116+
117117 diagnostics .withExecutablePath (executablePath );
118118 return executablePath ;
119119 }
0 commit comments