diff --git a/rewrite-java/src/main/java/org/openrewrite/java/JavaParser.java b/rewrite-java/src/main/java/org/openrewrite/java/JavaParser.java index df27a6f4d01..62691fe30ff 100644 --- a/rewrite-java/src/main/java/org/openrewrite/java/JavaParser.java +++ b/rewrite-java/src/main/java/org/openrewrite/java/JavaParser.java @@ -37,10 +37,7 @@ import java.lang.reflect.Method; import java.net.URI; import java.nio.charset.Charset; -import java.nio.file.FileAlreadyExistsException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; +import java.nio.file.*; import java.util.*; import java.util.function.Function; import java.util.regex.Matcher; @@ -172,14 +169,14 @@ static List dependenciesFromResources(ExecutionContext ctx, String... arti if (jarPattern.matcher(resource.getPath()).find()) { try { Path artifact = resourceTarget.toPath().resolve(Paths.get(resource.getPath()).getFileName()); - - Files.copy( - requireNonNull(caller.getResourceAsStream("/" + resource.getPath())), - artifact - ); + if (!Files.exists(artifact)) { + Files.copy( + requireNonNull(caller.getResourceAsStream("/" + resource.getPath())), + artifact + ); + } missingArtifactNames.remove(artifactName); artifacts.add(artifact); - } catch (FileAlreadyExistsException ignore) { } catch (IOException e) { throw new UncheckedIOException(e); }