Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8283895

Cannot add service provider implementations in annotation processor

XMLWordPrintable

      ADDITIONAL SYSTEM INFORMATION :
      Ubuntu Linux (but valid on any platform)
      Using Java 11, 17, 18 and 19 loom builds

      A DESCRIPTION OF THE PROBLEM :
      I have an application using `module-info.java` that uses annotation processor. This annotation processor generates classes that are an implementation of a `ServiceLoader` provider interface.
      Before the Java Module System, I could just generate `META-INF/services` records for these classes to add generated implementations. With the Java Module System, there is no possible way to add a service, as `module-info.java` cannot be generated (filer throws an exception), nor modified (as there is no API for it).
      This is needed to implement a wide variaty of use cases, such as compile time injection (where service loader is used to discover "beans" at runtime).
      The only workaround would be to create a custom service loader mechanism, which implies discovery of resources at runtime and reflection to instantiate the classes (which is the whole reason for existence of `ServiceLoader`).


            Unassigned Unassigned
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: