Skip to content

Automatically configure ServiceLoader providers

License

Notifications You must be signed in to change notification settings

hunterwb/ServiceScanner

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

44 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ServiceScanner

Automatically configure ServiceLoader providers

A Java annotation processor which automatically discovers all ServiceLoader providers and generates the META-INF/services provider-configuration files. A class is determined to be a service provider if it has a public no-argument constructor and is assignable to a service type. The canonical names of all services must be passed to javac using the following format: -Aservices=com.example.Service1,com.example.Service2. Supports Java 6+.

Maven usage:
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.8.1</version>
            <configuration>
                <annotationProcessorPaths>
                    <path>
                        <groupId>com.hunterwb</groupId>
                        <artifactId>servicescanner</artifactId>
                        <version>0.1.3</version>
                    </path>
                </annotationProcessorPaths>
                <showWarnings>true</showWarnings>
                <compilerArgs>
                    <arg>-Aservices=com.example.Service1,com.example.Service2</arg>
                </compilerArgs>
            </configuration>
        </plugin>
    </plugins>
</build>
Gradle usage:
dependencies {
    annotationProcessor 'com.hunterwb:servicescanner:0.1.3'
}

compileJava {
    options.compilerArgs.add('-Aservices=com.example.Service1,com.example.Service2')
}