https://github.com/emilyy-dev/annotated-service-provider
Define Java service providers by annotating them directly
https://github.com/emilyy-dev/annotated-service-provider
annotation annotation-processor java service-provider serviceloader
Last synced: 3 months ago
JSON representation
Define Java service providers by annotating them directly
- Host: GitHub
- URL: https://github.com/emilyy-dev/annotated-service-provider
- Owner: emilyy-dev
- License: mit
- Created: 2021-10-12T04:09:59.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2021-10-19T02:18:11.000Z (almost 4 years ago)
- Last Synced: 2025-04-07T17:46:36.771Z (6 months ago)
- Topics: annotation, annotation-processor, java, service-provider, serviceloader
- Language: Java
- Homepage:
- Size: 46.9 KB
- Stars: 5
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: changelog.txt
- License: LICENSE.txt
Awesome Lists containing this project
README
# Annotated Service Provider
### Define JVM service providers by annotating the provider class directly.
[](https://search.maven.org/artifact/io.github.emilyy-dev/annotated-service-provider)
[](https://s01.oss.sonatype.org/content/repositories/snapshots/io/github/emilyy-dev/annotated-service-provider/)
[](https://github.com/emilyy-dev/annotated-service-provider/blob/main/LICENSE.txt)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
```java
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](https://docs.oracle.com/javase/8/docs/api/java/util/ServiceLoader.html) 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
```groovy
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`**](https://kotlinlang.org/docs/kapt.html) to use
> annotation processors instead.* Using Maven
```xml
org.apache.maven.plugins
maven-compiler-plugin
3.8.1
io.github.emilyy-dev
annotated-service-provider-processor
{version}
io.github.emilyy-dev
annotated-service-provider
{version}
provided
```
### License
This project is licensed under the MIT license.