This is an automated email from the ASF dual-hosted git repository.

slachiewicz pushed a commit to branch maven-compiler-plugin-3.x
in repository https://gitbox.apache.org/repos/asf/maven-compiler-plugin.git


The following commit(s) were added to refs/heads/maven-compiler-plugin-3.x by 
this push:
     new aaeb9c6  [MCOMPILER-540] useIncrementalCompilation=false may add 
generated sources to the sources list (#192)
aaeb9c6 is described below

commit aaeb9c6079c6ed012d71e660465d99ee1806a12b
Author: Daniel Mensinger <[email protected]>
AuthorDate: Sun Jan 11 22:52:12 2026 +0100

    [MCOMPILER-540] useIncrementalCompilation=false may add generated sources 
to the sources list (#192)
---
 src/it/MCOMPILER-540/code/pom.xml                  | 87 ++++++++++++++++++++++
 .../code/src/main/java/bar/MyAnnotatedClass.java   | 29 ++++++++
 src/it/MCOMPILER-540/invoker.properties            | 23 ++++++
 src/it/MCOMPILER-540/pom.xml                       | 70 +++++++++++++++++
 src/it/MCOMPILER-540/processor/pom.xml             | 43 +++++++++++
 .../processor/src/main/java/foo/MyAnnotation.java  | 28 +++++++
 .../processor/src/main/java/foo/MyProcessor.java   | 67 +++++++++++++++++
 .../services/javax.annotation.processing.Processor | 18 +++++
 .../plugin/compiler/AbstractCompilerMojo.java      | 12 +++
 9 files changed, 377 insertions(+)

diff --git a/src/it/MCOMPILER-540/code/pom.xml 
b/src/it/MCOMPILER-540/code/pom.xml
new file mode 100644
index 0000000..e0847e0
--- /dev/null
+++ b/src/it/MCOMPILER-540/code/pom.xml
@@ -0,0 +1,87 @@
+<?xml version="1.0"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one
+  or more contributor license agreements.  See the NOTICE file
+  distributed with this work for additional information
+  regarding copyright ownership.  The ASF licenses this file
+  to you under the Apache License, Version 2.0 (the
+  "License"); you may not use this file except in compliance
+  with the License.  You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing,
+  software distributed under the License is distributed on an
+  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  KIND, either express or implied.  See the License for the
+  specific language governing permissions and limitations
+  under the License.
+-->
+<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
https://maven.apache.org/xsd/maven-4.0.0.xsd"; 
xmlns="http://maven.apache.org/POM/4.0.0";
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";>
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <groupId>foo</groupId>
+    <artifactId>bar</artifactId>
+    <version>1.0-SNAPSHOT</version>
+  </parent>
+  <version>1.0-SNAPSHOT</version>
+  <packaging>jar</packaging>
+  <artifactId>code</artifactId>
+
+  <build>
+    <pluginManagement>
+      <plugins>
+        <plugin>
+          <groupId>org.apache.maven.plugins</groupId>
+          <artifactId>maven-antrun-plugin</artifactId>
+          <version>3.1.0</version>
+        </plugin>
+      </plugins>
+    </pluginManagement>
+  </build>
+
+  <profiles>
+    <profile>
+      <id>actualBuild</id>
+      <dependencies>
+        <dependency>
+          <groupId>foo</groupId>
+          <artifactId>processor</artifactId>
+          <version>1.0-SNAPSHOT</version>
+          <scope>provided</scope>
+        </dependency>
+      </dependencies>
+    </profile>
+
+    <profile>
+      <id>touchFiles</id>
+      <activation>
+        <activeByDefault>false</activeByDefault>
+      </activation>
+      <build>
+        <plugins>
+          <plugin>
+            <groupId>org.apache.maven.plugins</groupId>
+            <artifactId>maven-antrun-plugin</artifactId>
+            <executions>
+              <execution>
+                <id>touch-gen-src</id>
+                <goals>
+                  <goal>run</goal>
+                </goals>
+                <phase>validate</phase>
+                <configuration>
+                  <target>
+                    <touch 
file="${basedir}/target/generated-sources/annotations/bar/MyGeneratedClass.java"/>
+                    <touch 
file="${project.build.sourceDirectory}/bar/MyAnnotatedClass.java"/>
+                  </target>
+                </configuration>
+              </execution>
+            </executions>
+          </plugin>
+        </plugins>
+      </build>
+    </profile>
+  </profiles>
+</project>
diff --git a/src/it/MCOMPILER-540/code/src/main/java/bar/MyAnnotatedClass.java 
b/src/it/MCOMPILER-540/code/src/main/java/bar/MyAnnotatedClass.java
new file mode 100644
index 0000000..cc4126d
--- /dev/null
+++ b/src/it/MCOMPILER-540/code/src/main/java/bar/MyAnnotatedClass.java
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package bar;
+
+import foo.MyAnnotation;
+
+@MyAnnotation
+public class MyAnnotatedClass {
+    MyGeneratedClass generatedClass = new MyGeneratedClass();
+
+    // foo
+
+}
diff --git a/src/it/MCOMPILER-540/invoker.properties 
b/src/it/MCOMPILER-540/invoker.properties
new file mode 100644
index 0000000..bf1b594
--- /dev/null
+++ b/src/it/MCOMPILER-540/invoker.properties
@@ -0,0 +1,23 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+# NOTE: The first time, we run up to "integration-test" phase which includes 
the AntRun execution which saves the
+# timestamp of the first JAR for comparison with the timestamp of the JAR from 
the final "package" invocation.
+# Note:
+invoker.goals.1 = clean compile -PactualBuild
+invoker.goals.2 = validate -PtouchFiles
+invoker.goals.3 = compile -PactualBuild
diff --git a/src/it/MCOMPILER-540/pom.xml b/src/it/MCOMPILER-540/pom.xml
new file mode 100644
index 0000000..3f3e577
--- /dev/null
+++ b/src/it/MCOMPILER-540/pom.xml
@@ -0,0 +1,70 @@
+<?xml version="1.0"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one
+  or more contributor license agreements.  See the NOTICE file
+  distributed with this work for additional information
+  regarding copyright ownership.  The ASF licenses this file
+  to you under the Apache License, Version 2.0 (the
+  "License"); you may not use this file except in compliance
+  with the License.  You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing,
+  software distributed under the License is distributed on an
+  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  KIND, either express or implied.  See the License for the
+  specific language governing permissions and limitations
+  under the License.
+-->
+<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
https://maven.apache.org/xsd/maven-4.0.0.xsd"; 
xmlns="http://maven.apache.org/POM/4.0.0";
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";>
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>foo</groupId>
+  <artifactId>bar</artifactId>
+  <version>1.0-SNAPSHOT</version>
+  <packaging>pom</packaging>
+
+  <properties>
+    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+  </properties>
+
+  <modules>
+    <module>processor</module>
+    <module>code</module>
+  </modules>
+
+  <build>
+    <pluginManagement>
+      <plugins>
+        <plugin>
+          <groupId>org.apache.maven.plugins</groupId>
+          <artifactId>maven-compiler-plugin</artifactId>
+          <version>@project.version@</version>
+        </plugin>
+      </plugins>
+    </pluginManagement>
+
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-compiler-plugin</artifactId>
+        <configuration>
+          <encoding>UTF-8</encoding>
+          <showWarnings>true</showWarnings>
+          <showDeprecation>true</showDeprecation>
+          <fork>true</fork> <!-- Change this to false and the 
Diagnostic.Kind.NOTE messages show up -->
+          <useIncrementalCompilation>false</useIncrementalCompilation>
+          <compilerArgs combine.children="append">
+            <arg>-Xlint:all,-processing</arg>
+            <arg>-Xdoclint:all,-missing,-accessibility</arg>
+            <arg>-Xmaxerrs</arg>
+            <arg>2147483647</arg>
+            <arg>-Xmaxwarns</arg>
+            <arg>2147483647</arg>
+          </compilerArgs>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+</project>
diff --git a/src/it/MCOMPILER-540/processor/pom.xml 
b/src/it/MCOMPILER-540/processor/pom.xml
new file mode 100644
index 0000000..8c49c7d
--- /dev/null
+++ b/src/it/MCOMPILER-540/processor/pom.xml
@@ -0,0 +1,43 @@
+<?xml version="1.0"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one
+  or more contributor license agreements.  See the NOTICE file
+  distributed with this work for additional information
+  regarding copyright ownership.  The ASF licenses this file
+  to you under the Apache License, Version 2.0 (the
+  "License"); you may not use this file except in compliance
+  with the License.  You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing,
+  software distributed under the License is distributed on an
+  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  KIND, either express or implied.  See the License for the
+  specific language governing permissions and limitations
+  under the License.
+-->
+<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
https://maven.apache.org/xsd/maven-4.0.0.xsd"; 
xmlns="http://maven.apache.org/POM/4.0.0";
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";>
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <groupId>foo</groupId>
+    <artifactId>bar</artifactId>
+    <version>1.0-SNAPSHOT</version>
+  </parent>
+  <version>1.0-SNAPSHOT</version>
+  <artifactId>processor</artifactId>
+  <packaging>jar</packaging>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-compiler-plugin</artifactId>
+        <configuration>
+          <proc>none</proc>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+</project>
diff --git a/src/it/MCOMPILER-540/processor/src/main/java/foo/MyAnnotation.java 
b/src/it/MCOMPILER-540/processor/src/main/java/foo/MyAnnotation.java
new file mode 100644
index 0000000..88431ae
--- /dev/null
+++ b/src/it/MCOMPILER-540/processor/src/main/java/foo/MyAnnotation.java
@@ -0,0 +1,28 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package foo;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Retention(RetentionPolicy.SOURCE)
+@Target(ElementType.TYPE)
+public @interface MyAnnotation {}
diff --git a/src/it/MCOMPILER-540/processor/src/main/java/foo/MyProcessor.java 
b/src/it/MCOMPILER-540/processor/src/main/java/foo/MyProcessor.java
new file mode 100644
index 0000000..88db357
--- /dev/null
+++ b/src/it/MCOMPILER-540/processor/src/main/java/foo/MyProcessor.java
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package foo;
+
+import javax.annotation.processing.*;
+import javax.lang.model.SourceVersion;
+import javax.lang.model.element.TypeElement;
+import javax.tools.Diagnostic;
+import javax.tools.JavaFileObject;
+
+import java.io.IOException;
+import java.io.Writer;
+import java.util.Set;
+
+@SupportedAnnotationTypes("foo.MyAnnotation")
+public class MyProcessor extends AbstractProcessor {
+
+    private int procRun = 0;
+
+    @Override
+    public SourceVersion getSupportedSourceVersion() {
+        return SourceVersion.latestSupported();
+    }
+
+    @Override
+    public boolean process(Set<? extends TypeElement> annotations, 
RoundEnvironment roundEnv) {
+        try {
+            generate(annotations, roundEnv);
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        }
+
+        return false;
+    }
+
+    private void generate(Set<? extends TypeElement> annotations, 
RoundEnvironment roundEnv) throws IOException {
+        Messager msg = processingEnv.getMessager();
+        msg.printMessage(Diagnostic.Kind.NOTE, String.format("[%d]: Hello 
Info", procRun));
+        msg.printMessage(Diagnostic.Kind.WARNING, String.format("[%d]: Hello 
Warning", procRun));
+        procRun++;
+
+        if (procRun > 1) {
+            return;
+        }
+
+        JavaFileObject file = 
processingEnv.getFiler().createSourceFile("bar.MyGeneratedClass");
+        try (Writer writer = file.openWriter()) {
+            writer.write("package bar;\npublic class MyGeneratedClass {}");
+        }
+    }
+}
diff --git 
a/src/it/MCOMPILER-540/processor/src/main/resources/META-INF/services/javax.annotation.processing.Processor
 
b/src/it/MCOMPILER-540/processor/src/main/resources/META-INF/services/javax.annotation.processing.Processor
new file mode 100644
index 0000000..678af7b
--- /dev/null
+++ 
b/src/it/MCOMPILER-540/processor/src/main/resources/META-INF/services/javax.annotation.processing.Processor
@@ -0,0 +1,18 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+foo.MyProcessor
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 e9290bc..1aebf4c 100644
--- a/src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java
+++ b/src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java
@@ -1000,6 +1000,7 @@ public abstract class AbstractCompilerMojo extends 
AbstractMojo {
                 return;
             }
 
+            staleSources = filterSourceFiles(staleSources);
             compilerConfiguration.setSourceFiles(staleSources);
 
             try {
@@ -1887,6 +1888,17 @@ public abstract class AbstractCompilerMojo extends 
AbstractMojo {
         targetOrReleaseSet = true;
     }
 
+    private Set<File> filterSourceFiles(Set<File> sourceFiles) {
+        final File generatedSources = getGeneratedSourcesDirectory();
+        if (generatedSources == null) {
+            return sourceFiles;
+        }
+        final String generatedSourcesPath = generatedSources.getAbsolutePath();
+        return sourceFiles.stream()
+                .filter(x -> 
!x.getAbsolutePath().startsWith(generatedSourcesPath))
+                .collect(Collectors.toSet());
+    }
+
     final String getImplicit() {
         return implicit;
     }

Reply via email to