diff --git a/native-gradle-plugin/src/main/java/org/graalvm/buildtools/gradle/internal/NativeImageCommandLineProvider.java b/native-gradle-plugin/src/main/java/org/graalvm/buildtools/gradle/internal/NativeImageCommandLineProvider.java index ef9691497..1ea22d346 100644 --- a/native-gradle-plugin/src/main/java/org/graalvm/buildtools/gradle/internal/NativeImageCommandLineProvider.java +++ b/native-gradle-plugin/src/main/java/org/graalvm/buildtools/gradle/internal/NativeImageCommandLineProvider.java @@ -109,12 +109,8 @@ public List asArguments() { List cliArgs = new ArrayList<>(20); cliArgs.add("-cp"); - if (classpathJar.isPresent()) { - cliArgs.add(classpathJar.get().getAsFile().getAbsolutePath()); - } else { - cliArgs.add(options.getClasspath().getAsPath()); - } - + String classpathString = buildClasspathString(options); + cliArgs.add(classpathString); appendBooleanOption(cliArgs, options.getDebug(), "-H:GenerateDebugInfo=1"); appendBooleanOption(cliArgs, options.getFallback().map(NEGATE), "--no-fallback"); appendBooleanOption(cliArgs, options.getVerbose(), "--verbose"); @@ -152,6 +148,26 @@ public List asArguments() { return Collections.unmodifiableList(cliArgs); } + /** + * Builds a classpath string from the given classpath elements. + * This can be overridden by subclasses for special needs. For + * example, the Micronaut plugin requires this because it's going + * to build images within a docker container, which makes it so + * that the paths in the options are invalid (they would be prefixed + * by a Windows path). + * @param options the native options + * @return the classpath string + */ + protected String buildClasspathString(NativeImageOptions options) { + String classpathString; + if (classpathJar.isPresent()) { + classpathString = classpathJar.get().getAsFile().getAbsolutePath(); + } else { + classpathString = options.getClasspath().getAsPath(); + } + return classpathString; + } + private static void appendBooleanOption(List cliArgs, Provider provider, String whenTrue) { if (provider.get()) { cliArgs.add(whenTrue);