diff --git a/native-maven-plugin/src/functionalTest/groovy/org/graalvm/buildtools/maven/JavaApplicationFunctionalTest.groovy b/native-maven-plugin/src/functionalTest/groovy/org/graalvm/buildtools/maven/JavaApplicationFunctionalTest.groovy index f546e1434..2b8aa6280 100644 --- a/native-maven-plugin/src/functionalTest/groovy/org/graalvm/buildtools/maven/JavaApplicationFunctionalTest.groovy +++ b/native-maven-plugin/src/functionalTest/groovy/org/graalvm/buildtools/maven/JavaApplicationFunctionalTest.groovy @@ -121,6 +121,14 @@ class JavaApplicationFunctionalTest extends AbstractGraalVMMavenFunctionalTest { then: buildSucceeded outputContains "Args file written to: target" + File.separator + "native-image" + + when: + mvn '-DquickBuild', '-Pnative', 'native:write-args-file' + + then: + buildSucceeded + outputContains "Args file written to: target" + File.separator + "native-image" + file("target/").listFiles().findAll(x->x.name.contains("native-image") && x.name.endsWith(".args")).size() == 1 } } diff --git a/native-maven-plugin/src/main/java/org/graalvm/buildtools/maven/WriteArgsFileMojo.java b/native-maven-plugin/src/main/java/org/graalvm/buildtools/maven/WriteArgsFileMojo.java index 885e1b361..15e79f5d5 100644 --- a/native-maven-plugin/src/main/java/org/graalvm/buildtools/maven/WriteArgsFileMojo.java +++ b/native-maven-plugin/src/main/java/org/graalvm/buildtools/maven/WriteArgsFileMojo.java @@ -47,7 +47,11 @@ import org.graalvm.buildtools.utils.NativeImageUtils; import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; import java.util.List; +import java.util.stream.Stream; /** * Persists the arguments file to be used by the native-image command. This can be useful in situations where @@ -67,6 +71,24 @@ public class WriteArgsFileMojo extends NativeCompileNoForkMojo { @Override public void execute() throws MojoExecutionException { List args = getBuildArgs(); + + getLog().debug("Cleaning old native image build args"); + + try (Stream listStream = Files.list(outputDirectory.toPath())) { + listStream.map(path -> path.getFileName().toString()) + .filter(f -> f.startsWith("native-image") && f.endsWith("args")) + .map(outputDirectory.toPath()::resolve) + .forEach(file -> { + try { + Files.delete(file); + } catch (IOException e) { + throw new RuntimeException(e); + } + }); + } catch (IOException e) { + throw new MojoExecutionException(e); + } + List conversionResult = NativeImageUtils.convertToArgsFile(args, outputDirectory.toPath()); if (conversionResult.size() == 1) { String argsFileName = conversionResult.get(0).replace("@", "");