From a201f7bfacdc9f703f3bdaf7480426256f107d6c Mon Sep 17 00:00:00 2001 From: Vaclav Haisman Date: Sun, 12 Jul 2026 16:44:46 +0200 Subject: [PATCH 1/2] Ignore empty annotation processor lists Fixes #892. --- .../plugin/compiler/AbstractCompilerMojo.java | 6 ++- .../plugin/compiler/CompilerMojoTest.java | 11 ++++++ .../plugin-config.xml | 38 +++++++++++++++++++ .../src/main/java/TestCompile.java | 19 ++++++++++ 4 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 src/test/resources/unit/compiler-empty-annotation-processors-test/plugin-config.xml create mode 100644 src/test/resources/unit/compiler-empty-annotation-processors-test/src/main/java/TestCompile.java 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 edb9ad7ed..53d10d28e 100644 --- a/src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java +++ b/src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java @@ -858,7 +858,11 @@ private void executeReal() throws MojoExecutionException, CompilationFailureExce compilerConfiguration.setSourceLocations(compileSourceRoots); - compilerConfiguration.setAnnotationProcessors(annotationProcessors); + String[] processors = annotationProcessors; + if (processors != null && Arrays.stream(processors).allMatch(StringUtils::isBlank)) { + processors = null; + } + compilerConfiguration.setAnnotationProcessors(processors); compilerConfiguration.setProcessorPathEntries(resolveProcessorPathEntries()); diff --git a/src/test/java/org/apache/maven/plugin/compiler/CompilerMojoTest.java b/src/test/java/org/apache/maven/plugin/compiler/CompilerMojoTest.java index 260fd941e..b9f44cf93 100644 --- a/src/test/java/org/apache/maven/plugin/compiler/CompilerMojoTest.java +++ b/src/test/java/org/apache/maven/plugin/compiler/CompilerMojoTest.java @@ -80,6 +80,17 @@ void testCompilerBasic(CompilerMojo compilerMojo) throws Exception { assertTrue(testClass::exists); } + @Test + @InjectMojo(goal = COMPILE, pom = "classpath:/unit/compiler-empty-annotation-processors-test/plugin-config.xml") + void testCompilerEmptyAnnotationProcessors(CompilerMojo compilerMojo) throws Exception { + setUpCompilerMojoTestEnv(compilerMojo); + + compilerMojo.execute(); + + File testClass = new File(compilerMojo.getOutputDirectory(), "TestCompile.class"); + assertTrue(testClass::exists); + } + @Test @InjectMojo(goal = COMPILE, pom = "classpath:/unit/compiler-basic-sourcetarget/plugin-config.xml") void testCompilerBasicSourceTarget(CompilerMojo compilerMojo) throws Exception { diff --git a/src/test/resources/unit/compiler-empty-annotation-processors-test/plugin-config.xml b/src/test/resources/unit/compiler-empty-annotation-processors-test/plugin-config.xml new file mode 100644 index 000000000..205cc47a5 --- /dev/null +++ b/src/test/resources/unit/compiler-empty-annotation-processors-test/plugin-config.xml @@ -0,0 +1,38 @@ + + + + + + + maven-compiler-plugin + + + ${basedir}/target/test-classes/unit/compiler-empty-annotation-processors-test/src/main/java + + + + javac + ${basedir}/target/test/unit/compiler-empty-annotation-processors-test/target/classes + ${basedir}/target/test/unit/compiler-empty-annotation-processors-test/target + + + + + diff --git a/src/test/resources/unit/compiler-empty-annotation-processors-test/src/main/java/TestCompile.java b/src/test/resources/unit/compiler-empty-annotation-processors-test/src/main/java/TestCompile.java new file mode 100644 index 000000000..fd3ba1f36 --- /dev/null +++ b/src/test/resources/unit/compiler-empty-annotation-processors-test/src/main/java/TestCompile.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 TestCompile {} From 2c31c0d05bcd1314ffcaa2d889fc14198028ef7d Mon Sep 17 00:00:00 2001 From: Vaclav Haisman Date: Tue, 28 Jul 2026 14:39:39 +0200 Subject: [PATCH 2/2] Filter blank annotation processor names --- .../plugin/compiler/AbstractCompilerMojo.java | 21 ++++++++++++++----- .../plugin/compiler/CompilerMojoTest.java | 11 ++++++++++ 2 files changed, 27 insertions(+), 5 deletions(-) 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 53d10d28e..cdf6ef2a7 100644 --- a/src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java +++ b/src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java @@ -858,11 +858,7 @@ private void executeReal() throws MojoExecutionException, CompilationFailureExce compilerConfiguration.setSourceLocations(compileSourceRoots); - String[] processors = annotationProcessors; - if (processors != null && Arrays.stream(processors).allMatch(StringUtils::isBlank)) { - processors = null; - } - compilerConfiguration.setAnnotationProcessors(processors); + compilerConfiguration.setAnnotationProcessors(normalizeAnnotationProcessors(annotationProcessors)); compilerConfiguration.setProcessorPathEntries(resolveProcessorPathEntries()); @@ -1609,6 +1605,21 @@ private static List removeEmptyCompileSourceRoots(List compileSo return newCompileSourceRootsList; } + /** + * Removes blank annotation processor names. + * + * @param processors the configured annotation processor names, or {@code null}. + * @return the non-blank annotation processor names, or {@code null} if none remain. + */ + static String[] normalizeAnnotationProcessors(String[] processors) { + if (processors != null) { + processors = Arrays.stream(processors) + .filter(processor -> !StringUtils.isBlank(processor)) + .toArray(String[]::new); + } + return processors == null || processors.length == 0 ? null : processors; + } + /** * We just compare the timestamps of all local dependency files (inter-module dependency classpath) and the own * generated classes and if we got a file which is >= the build-started timestamp, then we caught a file which diff --git a/src/test/java/org/apache/maven/plugin/compiler/CompilerMojoTest.java b/src/test/java/org/apache/maven/plugin/compiler/CompilerMojoTest.java index b9f44cf93..fff627624 100644 --- a/src/test/java/org/apache/maven/plugin/compiler/CompilerMojoTest.java +++ b/src/test/java/org/apache/maven/plugin/compiler/CompilerMojoTest.java @@ -35,6 +35,7 @@ import static org.apache.maven.api.plugin.testing.MojoExtension.setVariableValueToObject; import static org.apache.maven.plugin.compiler.MojoTestUtils.getMockMavenProject; import static org.apache.maven.plugin.compiler.MojoTestUtils.getMockMavenSession; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotNull; @@ -91,6 +92,16 @@ void testCompilerEmptyAnnotationProcessors(CompilerMojo compilerMojo) throws Exc assertTrue(testClass::exists); } + @Test + void testNormalizeAnnotationProcessors() { + assertNull(AbstractCompilerMojo.normalizeAnnotationProcessors(null)); + assertNull(AbstractCompilerMojo.normalizeAnnotationProcessors(new String[] {"", " "})); + assertArrayEquals( + new String[] {"com.example.First", "com.example.Second"}, + AbstractCompilerMojo.normalizeAnnotationProcessors( + new String[] {"", "com.example.First", " ", "com.example.Second"})); + } + @Test @InjectMojo(goal = COMPILE, pom = "classpath:/unit/compiler-basic-sourcetarget/plugin-config.xml") void testCompilerBasicSourceTarget(CompilerMojo compilerMojo) throws Exception {