Skip to content

Commit fd37f09

Browse files
authored
[MCOMPILER-333] Cleanup generated source files (#214)
Signed-off-by: Jorge Solórzano <jorsol@gmail.com>
1 parent d721f0f commit fd37f09

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import java.util.ArrayList;
3131
import java.util.Arrays;
3232
import java.util.Collections;
33+
import java.util.Comparator;
3334
import java.util.Date;
3435
import java.util.HashSet;
3536
import java.util.Iterator;
@@ -41,6 +42,7 @@
4142
import java.util.Properties;
4243
import java.util.Set;
4344
import java.util.stream.Collectors;
45+
import java.util.stream.Stream;
4446

4547
import org.apache.maven.RepositoryUtils;
4648
import org.apache.maven.artifact.handler.ArtifactHandler;
@@ -1173,6 +1175,17 @@ public void execute() throws MojoExecutionException, CompilationFailureException
11731175
if (useIncrementalCompilation) {
11741176
incrementalBuildHelperRequest.outputDirectory(getOutputDirectory());
11751177

1178+
// Cleanup the generated source files created by annotation processing
1179+
// they are regenerated by the java compiler.
1180+
if (getGeneratedSourcesDirectory() != null) {
1181+
try (Stream<Path> walk =
1182+
Files.walk(getGeneratedSourcesDirectory().toPath())) {
1183+
walk.sorted(Comparator.reverseOrder()).map(Path::toFile).forEach(File::delete);
1184+
} catch (IOException ex) {
1185+
getLog().warn("I/O error deleting the annotation processing generated files: " + ex.getMessage());
1186+
}
1187+
}
1188+
11761189
incrementalBuildHelper.beforeRebuildExecution(incrementalBuildHelperRequest);
11771190

11781191
getLog().debug("incrementalBuildHelper#beforeRebuildExecution");

0 commit comments

Comments
 (0)