You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Mansour Al Akeel <ma...@gmail.com> on 2025/11/05 06:05:57 UTC
Compiler Plugin with ServiceProvider
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.
Re: Compiler Plugin with ServiceProvider
Posted by Mansour Al Akeel <ma...@gmail.com>.
Thank you all for looking into this. For users facing the same issue, Han's
suggestion worked like a charm without additional plugins. The solution was
to move the execution of resource-plugin after compilation or during
preparing the package.
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<groupId>org.apache.maven.plugins</groupId>
<version>3.3.1</version>
<executions>
<execution>
<id>default-resources</id>
<phase>process-classes</phase>
</execution>
</executions>
</plugin>
On Wed, Nov 5, 2025 at 5:15 AM Hans Aikema <ha...@aikebah.net.invalid>
wrote:
>
>
> > On 5 Nov 2025, at 11:02, Hans Aikema <ha...@aikebah.net.INVALID>
> wrote:
> >
> > Or alternatively modify the sequence and move the execution of the
> resources-plugin in the prepare-package phase so that the META-INF/services
> is only copied AFTER you’ve compiled your plugin class
> >
>
> Should’ve said been "move into process-classes phase", but I accidentally
> modified only the xml snippet after looking into the earliest possible spot
> to put the execution that would be after the compile phase
>
> See also
> https://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html#Lifecycle_Reference
> for the full details of the lifecycle sequence (and the default lifecycle
> bindings of plugins)
Re: Compiler Plugin with ServiceProvider
Posted by Hans Aikema <ha...@aikebah.net.INVALID>.
> On 5 Nov 2025, at 11:02, Hans Aikema <ha...@aikebah.net.INVALID> wrote:
>
> Or alternatively modify the sequence and move the execution of the resources-plugin in the prepare-package phase so that the META-INF/services is only copied AFTER you’ve compiled your plugin class
>
Should’ve said been "move into process-classes phase", but I accidentally modified only the xml snippet after looking into the earliest possible spot to put the execution that would be after the compile phase
See also https://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html#Lifecycle_Reference for the full details of the lifecycle sequence (and the default lifecycle bindings of plugins)
Re: Compiler Plugin with ServiceProvider
Posted by Hans Aikema <ha...@aikebah.net.INVALID>.
Or alternatively modify the sequence and move the execution of the resources-plugin in the prepare-package phase so that the META-INF/services is only copied AFTER you’ve compiled your plugin class
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<groupId>org.apache.maven.plugins</groupId>
<version>3.3.1</version>
<executions>
<execution>
<id>default-resources</id>
<phase>process-classes</phase>
</execution>
</executions>
</plugin>
> On 5 Nov 2025, at 10:31, Thomas Broyer <t....@gmail.com> wrote:
>
> 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 <ma...@gmail.com>
> 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>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org
Re: Compiler Plugin with ServiceProvider
Posted by Thomas Broyer <t....@gmail.com>.
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 <ma...@gmail.com>
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>
Re: Compiler Plugin with ServiceProvider
Posted by Martin Desruisseaux <ma...@geomatys.com.INVALID>.
Hello Mansour
Le 05/11/2025 à 07:05, Mansour Al Akeel a écrit :
> (…snip…) The error I am getting:
> (…snip…) An exception has occurred in the compiler (21). Please file a bug against the Java compiler via the Java bug reporting page (…snip…)
This message come from javac rather than Maven. I suggest that you try
to compile on the command line with javac directly, without Maven, to
confirm. If the error still occur, then the links provided by the error
message may be the place to look for reporting.
Martin
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org