Domino Auto is a lightweight, annotation-processor-based service loader for GWT/J2CL applications. It scans
META-INF/services at compile time and generates a strongly typed loader class per service interface, avoiding
runtime reflection.
domino-auto-api: Provides the@DominoAutoannotation and GWT module.domino-auto-processor: Annotation processor that generates service loaders.
- You declare service interfaces and their implementations.
- You register implementations via
META-INF/services/<service-interface-FQN>(standard Java ServiceLoader files). - The annotation processor scans
META-INF/servicesat compile time. - For each included service interface, it generates
[ServiceInterface]_ServiceLoaderwith aload()method that returns aListof instantiated implementations.
The processor only generates loaders for services in the include list and not in the exclude list.
- Java 11 (see
maven.compiler.releaseinpom.xml) - Maven build
- Compatible with GWT3/J2CL
Add the API dependency:
<dependency>
<groupId>org.dominokit</groupId>
<artifactId>domino-auto-api</artifactId>
<version>[version]</version>
</dependency>Add the processor dependency (provided scope) or configure it via annotationProcessorPaths:
<dependency>
<groupId>org.dominokit</groupId>
<artifactId>domino-auto-processor</artifactId>
<version>[version]</version>
<scope>provided</scope>
</dependency>Or as a processor path in the compiler plugin:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>org.dominokit</groupId>
<artifactId>domino-auto-processor</artifactId>
<version>[version]</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>You must specify the packages of service interfaces to include. The include list applies to the service interface package, not implementation packages.
<compilerArgs>
<arg>-AdominoAutoInclude=com.example.services,org.example.more</arg>
<arg>-AdominoAutoExclude=com.example.services.internal</arg>
</compilerArgs>The processor resolves dominoAutoInclude and dominoAutoExclude in this order:
- JVM system properties, for example
-DdominoAutoInclude=com.example.services - Environment variables, using either
dominoAutoInclude/dominoAutoExcludeorDOMINO_AUTO_INCLUDE/DOMINO_AUTO_EXCLUDE - Annotation processor options, for example
-AdominoAutoInclude=...
@DominoAuto(include = {"com.example.services"}, exclude = {"com.example.services.internal"})
package com.example.services;
import org.dominokit.auto.DominoAuto;Notes:
- If no include list is provided, no loaders are generated.
- Exclude entries override includes by package prefix.
package com.example.services;
public interface SampleService {
void init();
}package com.example.services;
public class FooSampleServiceImpl implements SampleService {
public void init() {
// Do something here
}
}
package com.example.services;
public class BarSampleServiceImpl implements SampleService {
public void init() {
// Do something here
}
}Create META-INF/services/com.example.services.SampleService and list implementations:
com.example.services.FooSampleServiceImpl
com.example.services.BarSampleServiceImpl
Tip: You can also use com.google.auto.service.AutoService on implementations to generate the service files.
The processor generates SampleService_ServiceLoader:
public class SampleService_ServiceLoader {
public static List<SampleService> load() {
List<SampleService> services = new ArrayList<>();
services.add(new FooSampleServiceImpl());
services.add(new BarSampleServiceImpl());
return services;
}
}Usage:
SampleService_ServiceLoader.load()
.forEach(SampleService::init);- Naming:
[ServiceInterfaceSimpleName]_ServiceLoader - Package: same as the service interface
- API:
public static List<ServiceInterface> load()
- No generated loaders: confirm
dominoAutoIncludeis set or@DominoAutois present on a type or package. - Missing implementations: ensure
META-INF/services/<service-interface-FQN>is on the compile classpath. - IDE builds: configure annotation processor arguments in the IDE or delegate build to Maven.
Apache License, Version 2.0. See LICENSE.
