Gaia API GitHub

Maven plugin

gaia-maven-plugin has one goal, register-services, for projects that run on the module path.

It requires Maven 3.10.0 or later, and Java 21 or later: its descriptor declares both, so an older Maven refuses to run it. With the Maven Wrapper, set distributionUrl to Maven 3.10.0 or later.

Registering service providers

An annotation processor can list the service providers it generates in META-INF/services, which ServiceLoader reads on the class path. On the module path, ServiceLoader only finds the providers that module-info.java declares with provides, which a processor cannot add. The register-services goal adds them to the compiled module-info.class, after compilation:

<plugin>
  <groupId>be.imgn.gaia</groupId>
  <artifactId>gaia-maven-plugin</artifactId>
  <version>${gaia.version}</version>
  <executions>
    <execution>
      <goals>
        <goal>register-services</goal>
      </goals>
    </execution>
  </executions>
</plugin>

It runs in the process-classes phase:

The module still needs a uses directive where it calls ServiceLoader.load.

A processor built on gaia-processing that relies on the goal calls skipModuleCheck(service), so that it doesn't warn about the missing provides directive.

Parameters

Parameter Property Default Description
classesDirectory ${project.build.outputDirectory} The compiled classes, with module-info.class
services every file in META-INF/services The binary names of the services to register
skip gaia.registerServices.skip false Whether to skip the goal

To register only some services, list them. A listed service without a file in META-INF/services fails the build, as a misspelled name would otherwise be ignored:

<configuration>
  <services>
    <service>com.example.Plugin</service>
  </services>
</configuration>