oehme commented on PR #191:
URL:
https://github.com/apache/maven-compiler-plugin/pull/191#issuecomment-2713286426
You can do it without these hacks by moving the generated sources code after
the stale source scanning code. The important part is that it needs to happen
before the mojo returns, but after it has scanned its own sources.
```diff
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 5631892..27ea1f3 100644
---
a/src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java
+++
b/src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java
@@ -814,16 +814,6 @@ public abstract class AbstractCompilerMojo extends
AbstractMojo {
compilerConfiguration.setProc(proc);
- File generatedSourcesDirectory = getGeneratedSourcesDirectory();
- compilerConfiguration.setGeneratedSourcesDirectory(
- generatedSourcesDirectory != null ?
generatedSourcesDirectory.getAbsoluteFile() : null);
-
- if (generatedSourcesDirectory != null) {
- if (!generatedSourcesDirectory.exists()) {
- generatedSourcesDirectory.mkdirs();
- }
- }
-
compilerConfiguration.setSourceLocations(compileSourceRoots);
compilerConfiguration.setAnnotationProcessors(annotationProcessors);
@@ -933,9 +923,6 @@ public abstract class AbstractCompilerMojo extends
AbstractMojo {
getLog().info("Recompiling the module because of "
+ MessageUtils.buffer().strong(cause) + ".");
compilerConfiguration.setSourceFiles(sources);
- } else {
- getLog().info("Nothing to compile - all classes are up
to date.");
- return;
}
} catch (CompilerException e) {
throw new MojoExecutionException("Error while computing
stale sources.", e);
@@ -964,11 +951,6 @@ public abstract class AbstractCompilerMojo extends
AbstractMojo {
throw new MojoExecutionException("Error while computing
stale sources.", e);
}
- if (staleSources.isEmpty()) {
- getLog().info("Nothing to compile - all classes are up to
date.");
- return;
- }
-
compilerConfiguration.setSourceFiles(staleSources);
try {
@@ -988,6 +970,41 @@ public abstract class AbstractCompilerMojo extends
AbstractMojo {
}
}
+ File generatedSourcesDirectory = getGeneratedSourcesDirectory();
+ compilerConfiguration.setGeneratedSourcesDirectory(
+ generatedSourcesDirectory != null ?
generatedSourcesDirectory.getAbsoluteFile() : null);
+
+ if (generatedSourcesDirectory != null) {
+ if (!generatedSourcesDirectory.exists()) {
+ generatedSourcesDirectory.mkdirs();
+ }
+
+ String generatedSourcesPath =
generatedSourcesDirectory.getAbsolutePath();
+
+ if (isTestCompile()) {
+ getLog().debug("Adding " + generatedSourcesPath + " to
test-compile source roots:\n "
+ +
StringUtils.join(project.getTestCompileSourceRoots().iterator(), "\n "));
+
+ project.addTestCompileSourceRoot(generatedSourcesPath);
+
+ getLog().debug("New test-compile source roots:\n "
+ +
StringUtils.join(project.getTestCompileSourceRoots().iterator(), "\n "));
+ } else {
+ getLog().debug("Adding " + generatedSourcesPath + " to
compile source roots:\n "
+ +
StringUtils.join(project.getCompileSourceRoots().iterator(), "\n "));
+
+ project.addCompileSourceRoot(generatedSourcesPath);
+
+ getLog().debug("New compile source roots:\n "
+ +
StringUtils.join(project.getCompileSourceRoots().iterator(), "\n "));
+ }
+ }
+
+ if (compilerConfiguration.getSourceFiles().isEmpty()) {
+ getLog().info("Nothing to compile - all classes are up to
date.");
+ return;
+ }
+
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]