Class ServiceIndexGenerator
StaticOptimizations.Loader that
registers a ServiceIndex of the application's class path, so that service loading at run time does not
scan META-INF/services and META-INF/micronaut.
It is meant for the Micronaut Gradle and Maven plugins and Micronaut Runner, which call
generate(Request) in-process with plain paths, once the class path is final, and get class files back. It
is internal to them, not an API for applications or other build tools, and may change in any release.
The index is built by the application's own micronaut-core, with its ServiceIndexBuilder, in an
isolated class loader of the class path, whose parent is the platform class loader. The generated loader is
emitted with the ClassFile API, verified, and then run in that micronaut-core, which must rebuild exactly the
builder's index before anything is returned. No class of the application is loaded or initialised, and nothing of
the caller's class path is used. It needs micronaut-core 5.3.0 or later on the class path, and stands down with an
older one.
An index describes a class path that cannot change. So a caller runs it last, on the class path as it ships:
after Micronaut AOT, the merging of service files, Shadow or Shade, and any other rewrite of the jars, and before a
JDK AOT cache is trained. Whatever the ServiceIndexGenerator.Result.status(), the caller writes ServiceIndexGenerator.Result.entries() into the
holder, replacing entries of the same name, and deletes ServiceIndexGenerator.Result.removals(): a call that generates nothing
may still remove an earlier index from the holder. Callers do not run it for run tasks, tests or native images.
At run time, -Dmicronaut.service.index.enabled=false switches the index off, and
-Dmicronaut.service.index.validate=true checks it against a scan of the class path.
- Since:
- 3.2.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classThe class path an index is generated for: plain paths, no build tool type.static final classThe outcome of one generation: itsServiceIndexGenerator.Result.status(), oneServiceIndexGenerator.Result.message()for the caller to log, theServiceIndexGenerator.Result.entries()to write into the holder and theServiceIndexGenerator.Result.removals()to delete from it, which the caller applies whatever the status.static enumWhat a generation did. -
Method Summary
Modifier and TypeMethodDescriptionstatic ServiceIndexGenerator.Resultgenerate(ServiceIndexGenerator.Request request) Generates the service index of a class path, or says why it does not.
-
Method Details
-
generate
Generates the service index of a class path, or says why it does not.It never throws for anything about the inputs: a missing entry, an unreadable file and any failure of micronaut-core or of the emitter,
Errors included, are aServiceIndexGenerator.Resultthat generated nothing. Only aVirtualMachineErrorpropagates. It keeps no state, so calls are independent of each other; before it returns, the class loaders it opened are closed and the caller's context class loader is restored.- Parameters:
request- the class path and the entry that will hold the index- Returns:
- what was generated, or why nothing was
-