The problem is that Maven copies the src/main/resources/META-INF/services/
to the target/classes first, and (more importantly) adds target/classes to
the compile classpath, so when the compiler initializes, it will load that
service descriptor and fail because com.example.JavacPlugin is not found:
and indeed we're trying to compile it!
(what puzzles me though is that I thought javac would only load plugins
from the processor path, not the compile classpath)

As a workaround, you could use Google's AutoService [1], or Kohsuke's
metainf-services [2], to generate the service descriptor at compile-time
using an annotation processor; that way the file shouldn't exist in the
compile classpath when the compiler initializes (at least ErrorProne [3]
uses AutoService and doesn't suffer from that error)

Alternatively, configuring an explicitly empty processor path seems to
works (I tried
<compilerArgs><arg>-processorpath</arg><arg>:</arg></compilerArgs>; that
":" might not work on Windows though, where the path separator is different)

[1] https://github.com/google/auto/tree/main/service
[2] https://github.com/kohsuke/metainf-services
[3] https://errorprone.info/

On Wed, Nov 5, 2025 at 7:01 AM Mansour Al Akeel <[email protected]>
wrote:

> I am trying to build and package a sample JavacPlugin project into a jar
> file. The project can be inspected here:
>
> https://github.com/malakeel/java-compiler-plugin-example
>
>
> The error I am getting:
>
> [DEBUG] incrementalBuildHelper#beforeRebuildExecution
> [INFO] Compiling 2 source files with javac [debug verbose target 21] to
> target/classes
> An exception has occurred in the compiler (21). Please file a bug against
> the Java compiler via the Java bug reporting page (
> https://bugreport.java.com) after checking the Bug Database (
> https://bugs.java.com) for duplicates. Include your program, the following
> diagnostic, and the parameters passed to the Java compiler in your report.
> Thank you.
> java.util.ServiceConfigurationError: com.sun.source.util.Plugin: Provider
> com.example.JavacPlugin not found
> at java.base/java.util.ServiceLoader.fail(ServiceLoader.java:593)
>
> I am using openjdk version "21"
>
> While I understand the problem in general, I am unable to find the exact
> cause.
>
> Why is the compiler plugin unable to locate the given class, and what
> options do I need to set to make this work ?
> Thank you in advance.
>


-- 
Thomas Broyer
/tɔ.ma.bʁwa.je/
<https://ipa-reader.com/?text=t%C9%94.ma.b%CA%81wa.je&voice=Mathieu>

Reply via email to