From fd37f0934f152ea26a4d9b5c97dd3db6db465e7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Sol=C3=B3rzano?= Date: Thu, 7 Dec 2023 05:36:13 +0100 Subject: [PATCH] [MCOMPILER-333] Cleanup generated source files (#214) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jorge Solórzano --- .../maven/plugin/compiler/AbstractCompilerMojo.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java b/src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java index 298e5b7d..e9467651 100644 --- a/src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java +++ b/src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java @@ -30,6 +30,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; +import java.util.Comparator; import java.util.Date; import java.util.HashSet; import java.util.Iterator; @@ -41,6 +42,7 @@ import java.util.Properties; import java.util.Set; import java.util.stream.Collectors; +import java.util.stream.Stream; import org.apache.maven.RepositoryUtils; import org.apache.maven.artifact.handler.ArtifactHandler; @@ -1173,6 +1175,17 @@ public void execute() throws MojoExecutionException, CompilationFailureException if (useIncrementalCompilation) { incrementalBuildHelperRequest.outputDirectory(getOutputDirectory()); + // Cleanup the generated source files created by annotation processing + // they are regenerated by the java compiler. + if (getGeneratedSourcesDirectory() != null) { + try (Stream walk = + Files.walk(getGeneratedSourcesDirectory().toPath())) { + walk.sorted(Comparator.reverseOrder()).map(Path::toFile).forEach(File::delete); + } catch (IOException ex) { + getLog().warn("I/O error deleting the annotation processing generated files: " + ex.getMessage()); + } + } + incrementalBuildHelper.beforeRebuildExecution(incrementalBuildHelperRequest); getLog().debug("incrementalBuildHelper#beforeRebuildExecution");