diff --git a/src/it/MCOMPILER-567-kt/invoker.properties b/src/it/MCOMPILER-567-kt/invoker.properties
new file mode 100644
index 000000000..df01a38bd
--- /dev/null
+++ b/src/it/MCOMPILER-567-kt/invoker.properties
@@ -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.
+
+invoker.goals = clean compile
diff --git a/src/it/MCOMPILER-567-kt/pom.xml b/src/it/MCOMPILER-567-kt/pom.xml
new file mode 100644
index 000000000..a4cf61d07
--- /dev/null
+++ b/src/it/MCOMPILER-567-kt/pom.xml
@@ -0,0 +1,78 @@
+
+
+
+ 4.0.0
+ org.apache.maven.plugins
+ MCOMPILER-567-kt
+ MCOMPILER-567-kt
+ jar
+ 1.0-SNAPSHOT
+
+
+
+ org.jetbrains.kotlin
+ kotlin-stdlib
+ 1.9.21
+
+
+
+
+ ${project.basedir}/src/main/kotlin
+
+
+ org.jetbrains.kotlin
+ kotlin-maven-plugin
+ 1.9.21
+
+
+ compile
+
+ compile
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ @project.version@
+
+
+ default-compile
+ none
+
+
+ default-testCompile
+ none
+
+
+ java-compile
+ compile
+
+ compile
+
+
+
+
+
+
+
diff --git a/src/it/MCOMPILER-567-kt/src/main/kotlin/KotlinService.kt b/src/it/MCOMPILER-567-kt/src/main/kotlin/KotlinService.kt
new file mode 100644
index 000000000..31aee972e
--- /dev/null
+++ b/src/it/MCOMPILER-567-kt/src/main/kotlin/KotlinService.kt
@@ -0,0 +1,26 @@
+/*
+ * 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.
+ */
+
+class KotlinService {
+
+ fun sayHello() {
+ System.out.println("Kotlin says 'Hello World!'")
+ }
+
+}
diff --git a/src/it/MCOMPILER-567-kt/verify.groovy b/src/it/MCOMPILER-567-kt/verify.groovy
new file mode 100644
index 000000000..5d1960e09
--- /dev/null
+++ b/src/it/MCOMPILER-567-kt/verify.groovy
@@ -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.
+ */
+
+File target = new File( basedir, "target" );
+assert target.isDirectory()
+
+assert new File( target, "classes/KotlinService.class" ).exists();
diff --git a/src/it/MCOMPILER-567/invoker.properties b/src/it/MCOMPILER-567/invoker.properties
new file mode 100644
index 000000000..e08297d68
--- /dev/null
+++ b/src/it/MCOMPILER-567/invoker.properties
@@ -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.
+
+invoker.goals = test
diff --git a/src/it/MCOMPILER-567/pom.xml b/src/it/MCOMPILER-567/pom.xml
new file mode 100644
index 000000000..1c0af3c53
--- /dev/null
+++ b/src/it/MCOMPILER-567/pom.xml
@@ -0,0 +1,39 @@
+
+
+
+ 4.0.0
+ org.apache.maven.plugins
+ MCOMPILER-567
+ MCOMPILER-567
+ jar
+ 1.0-SNAPSHOT
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ @project.version@
+
+
+
+
diff --git a/src/it/MCOMPILER-567/src/main/java/Main.java b/src/it/MCOMPILER-567/src/main/java/Main.java
new file mode 100644
index 000000000..48add13bb
--- /dev/null
+++ b/src/it/MCOMPILER-567/src/main/java/Main.java
@@ -0,0 +1,19 @@
+/*
+ * 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.
+ */
+public class Main {}
diff --git a/src/it/MCOMPILER-567/src/test/java/.keep b/src/it/MCOMPILER-567/src/test/java/.keep
new file mode 100644
index 000000000..13a83393a
--- /dev/null
+++ b/src/it/MCOMPILER-567/src/test/java/.keep
@@ -0,0 +1,16 @@
+# 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.
diff --git a/src/it/MCOMPILER-567/verify.groovy b/src/it/MCOMPILER-567/verify.groovy
new file mode 100644
index 000000000..d71fe3411
--- /dev/null
+++ b/src/it/MCOMPILER-567/verify.groovy
@@ -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.
+ */
+
+File target = new File( basedir, "target" );
+assert target.isDirectory()
+
+assert new File( target, "classes/Main.class" ).exists();
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 fb285afb4..83fa7790f 100644
--- a/src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java
+++ b/src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java
@@ -1166,12 +1166,14 @@ 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.
+ // MCOMPILER-333: Cleanup the generated source files created by annotation processing
+ // to avoid issues with `javac` compiler when the source code is rebuild.
if (getGeneratedSourcesDirectory() != null) {
try (Stream walk =
Files.walk(getGeneratedSourcesDirectory().toPath())) {
walk.sorted(Comparator.reverseOrder()).map(Path::toFile).forEach(File::delete);
+ // MCOMPILER-567: The directory must already exist because javac does not create it.
+ Files.createDirectories(getGeneratedSourcesDirectory().toPath());
} catch (IOException ex) {
getLog().warn("I/O error deleting the annotation processing generated files: " + ex.getMessage());
}