https://github.com/francisdb/serviceloader-maven-plugin
Maven plugin for generating java serviceloader files
https://github.com/francisdb/serviceloader-maven-plugin
java maven-plugin serviceloader
Last synced: 10 days ago
JSON representation
Maven plugin for generating java serviceloader files
- Host: GitHub
- URL: https://github.com/francisdb/serviceloader-maven-plugin
- Owner: francisdb
- License: apache-2.0
- Created: 2010-11-04T19:40:46.000Z (over 14 years ago)
- Default Branch: master
- Last Pushed: 2024-06-01T19:47:57.000Z (11 months ago)
- Last Synced: 2025-04-18T01:18:25.830Z (12 days ago)
- Topics: java, maven-plugin, serviceloader
- Language: Java
- Homepage:
- Size: 203 KB
- Stars: 48
- Watchers: 6
- Forks: 15
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
[](https://github.com/francisdb/serviceloader-maven-plugin/actions)
[](https://maven-badges.herokuapp.com/maven-central/eu.somatik.serviceloader-maven-plugin/serviceloader-maven-plugin)This maven plugin generates services files for the ServiceLoader introduced in Java 6 :
https://docs.oracle.com/javase/9/docs/api/java/util/ServiceLoader.html# Use
for example:
```xml
eu.somatik.serviceloader-maven-plugin
serviceloader-maven-plugin
1.3.1
com.foo.Dictionary
com.foo.Operation
generate
```
this will generate these files:
* META-INF/services/com.foo.Dictionary
* META-INF/services/com.foo.Operationby scanning the generated classes and finding all non-abstract/non-interface implementations of the service interfaces. The plugin itself has no Java 6 dependency
# Excludes / includes
Additionally it is possible to filter implementation classes via includes and excludes section in the configuration. The class name notation is the same as for the services section.
for example:
```xml
eu.somatik.serviceloader-maven-plugin
serviceloader-maven-plugin
1.3.1
com.foo.Dictionary
com.foo.Operation
*.RightClass*
generate
```
This should add only implementation classes that begin with RightClass*.
# Missing Service Classes
The default action when a service class is missing is to fail the build.
If you want to ignore this service, you can use the `failOnMissingServiceClass` option (`true` by default).for example:
```xml
eu.somatik.serviceloader-maven-plugin
serviceloader-maven-plugin
1.3.1
false
com.foo.MissingService
generate
```
# Example
A example project is provided and can be run like this:
$ mvn clean install
...
[INFO] Generating service file .../example/target/classes/META-INF/services/eu.somatik.serviceloader.Operation
[INFO] + eu.somatik.serviceloader.SimpleOperation
...
$ java -jar target/example-1.0-SNAPSHOT.jar
Found service implementation: eu.somatik.serviceloader.SimpleOperation@579a19fd
Hello world# Release
see http://central.sonatype.org/pages/apache-maven.html#performing-a-release-deployment-with-the-maven-release-plugin
*Note: do `export GPG_TTY=$(tty)` first if you have `gpg: signing failed: Inappropriate ioctl for device` errors*
```
mvn -P release release:clean release:prepare
mvn -P release release:perform
```