Class ServiceProviderBuildItem

java.lang.Object
io.quarkus.builder.item.BuildItem
io.quarkus.builder.item.MultiBuildItem
io.quarkus.deployment.builditem.nativeimage.ServiceProviderBuildItem

public final class ServiceProviderBuildItem extends io.quarkus.builder.item.MultiBuildItem
Represents a Service Provider registration. When processed, it embeds the service interface descriptor (META-INF/services/...) in the native image and registers the classes returned by providers() for reflection (instantiation only).
  • Field Details

  • Constructor Details

    • ServiceProviderBuildItem

      public ServiceProviderBuildItem(String serviceInterfaceClassName, String... providerClassNames)
      Registers the specified service interface descriptor to be embedded and allow reflection (instantiation only) of the specified provider classes. Note that the service interface descriptor file has to exist and match the list of specified provider class names.
      Parameters:
      serviceInterfaceClassName - the interface whose service interface descriptor file we want to embed
      providerClassNames - the list of provider class names that must already be mentioned in the file
    • ServiceProviderBuildItem

      public ServiceProviderBuildItem(String serviceInterfaceClassName, Collection<String> providers)
      Registers the specified service interface descriptor to be embedded and allow reflection (instantiation only) of the specified provider classes. Note that the service interface descriptor file has to exist and match the list of specified provider class names.
      Parameters:
      serviceInterfaceClassName - the interface whose service interface descriptor file we want to embed
      providers - a collection of provider class names that must already be mentioned in the file
    • ServiceProviderBuildItem

      public ServiceProviderBuildItem(String serviceInterfaceClassName, List<String> providers)
      Registers the specified service interface descriptor to be embedded and allow reflection (instantiation only) of the specified provider classes. Note that the service interface descriptor file has to exist and match the list of specified provider class names.
      Parameters:
      serviceInterfaceClassName - the interface whose service interface descriptor file we want to embed
      providers - the list of provider class names that must already be mentioned in the file
  • Method Details

    • allProviders

      public static ServiceProviderBuildItem allProviders(String serviceInterfaceClassName, Path serviceInterfaceDescriptorFile) throws IOException
      Creates and returns a ServiceProviderBuildItem for the serviceInterfaceClassName by including all the providers that are listed in the service interface descriptor file.
      Parameters:
      serviceInterfaceClassName - the interface whose service interface descriptor file we want to embed
      serviceInterfaceDescriptorFile - the path to the service interface descriptor file
      Returns:
      Throws:
      IOException
    • allProvidersFromClassPath

      public static ServiceProviderBuildItem allProvidersFromClassPath(String serviceInterfaceClassName)
      Creates and returns a new ServiceProviderBuildItem for the given serviceInterfaceClassName by including all the providers that are listed in service interface descriptor files "META-INF/services/" + serviceInterfaceClassName findable in the Context Class Loader of the current thread.
      Parameters:
      serviceInterfaceClassName - the interface whose service interface descriptor file we want to embed
      Returns:
      a new ServiceProviderBuildItem
      Throws:
      RuntimeException - wrapping any IOExceptions thrown when accessing class path resources
    • allProvidersOfDependency

      public static Collection<ServiceProviderBuildItem> allProvidersOfDependency(Collection<io.quarkus.maven.dependency.ResolvedDependency> dependencies, io.quarkus.maven.dependency.ArtifactCoords artifactCoordinates)
      Creates a new Collection of ServiceProviderBuildItems for the selected artifact. It includes all the providers, that are contained in all the service interface descriptor files defined in "META-INF/services/" in the selected artifact.
      Parameters:
      dependencies - the resolved dependencies of the build
      artifactCoordinates - the coordinates of the artifact containing the service definitions
      Returns:
      a Collection of ServiceProviderBuildItems containing all the found service providers
    • allProvidersOfDependencies

      public static Collection<ServiceProviderBuildItem> allProvidersOfDependencies(Collection<io.quarkus.maven.dependency.ResolvedDependency> dependencies, Collection<io.quarkus.maven.dependency.ArtifactCoords> artifactCoordinatesCollection)
      Creates a new Collection of ServiceProviderBuildItems for the selected artifacts. It includes all the providers, that are contained in all the service interface descriptor files defined in "META-INF/services/" in all the selected artifacts.
      Parameters:
      dependencies - the resolved dependencies of the build
      artifactCoordinatesCollection - a Collection of coordinates of the artifacts containing the service definitions
      Returns:
      a Collection of ServiceProviderBuildItems containing all the found service providers
    • providers

      public List<String> providers()
      Returns:
      an immutable List of provider class names
    • serviceDescriptorFile

      public String serviceDescriptorFile()
      Returns:
      the resource path for the service descriptor file