Skip to content

emilyy-dev/annotated-service-provider

Repository files navigation

Annotated Service Provider

Define JVM service providers by annotating the provider class directly.

Maven Central Snapshot License

This annotation processor will add to the class-path services deployment (META-INF/services/) provider types that are annotated with the @ProvidesService annotation.

Example usage

package io.github.emilyydev.asp.demo;

import io.github.emilyydev.asp.ProvidesService;
import java.sql.Driver;

@ProvidesService(Driver.class)
public class SqlDriverImpl implements Driver {
  // implementation...
}

The annotation processor will read the class, ensure it meets the required criterion specified by the ServiceLoader documentation and add the provider type to the corresponding service file META-INF/services/java.sql.Driver as a new entry, in case that same jar file provides multiple providers for the same service.

Adding it to your project

ASP is released on Maven Central under two different artifacts:

  • The annotation artifact: io.github.emilyy-dev:annotated-service-provider:{version}.
  • The annotation processor artifact: io.github.emilyy-dev:annotated-service-provider-processor:{version}. The current version released is shown at the top of this readme. Snapshot builds can be found in OSS sonatype (https://s01.oss.sonatype.org/content/repositories/snapshots/)

Importing ASP to your project:

  • Using Gradle
repositories {
    mavenCentral()
}

dependencies {
    implementation("io.github.emilyy-dev:annotated-service-provider:{version}")
    annotationProcessor("io.github.emilyy-dev:annotated-service-provider-processor:{version}")
}

Note: if your project uses Kotlin you need to use kapt to use annotation processors instead.

  • Using Maven
<project>
    <!--  ...-->
    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.8.1</version>
                    <configuration>
                        <annotationProcessorPaths>
                            <path>
                                <groupId>io.github.emilyy-dev</groupId>
                                <artifactId>annotated-service-provider-processor</artifactId>
                                <version>{version}</version>
                            </path>
                        </annotationProcessorPaths>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>

    <dependencies>
        <dependency>
            <groupId>io.github.emilyy-dev</groupId>
            <artifactId>annotated-service-provider</artifactId>
            <version>{version}</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>
</project>

License

This project is licensed under the MIT license.