{"id":20340411,"url":"https://github.com/toolisticon/spi-annotation-processor","last_synced_at":"2025-04-11T23:23:18.112Z","repository":{"id":26930463,"uuid":"111035760","full_name":"toolisticon/SPI-Annotation-Processor","owner":"toolisticon","description":"Annotation processor that handles creation of service file and service locator","archived":false,"fork":false,"pushed_at":"2023-12-15T05:15:45.000Z","size":280,"stargazers_count":7,"open_issues_count":2,"forks_count":3,"subscribers_count":10,"default_branch":"develop","last_synced_at":"2025-03-25T19:14:39.205Z","etag":null,"topics":["annotation-processor","annotation-processor-toolkit","hacktoberfest","java","service","services","spi","spi-annotation-processor"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/toolisticon.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-11-16T23:57:59.000Z","updated_at":"2023-06-28T16:00:11.000Z","dependencies_parsed_at":"2023-12-15T06:29:37.776Z","dependency_job_id":"9680e0bb-31c4-412a-9629-fa02dd4d081d","html_url":"https://github.com/toolisticon/SPI-Annotation-Processor","commit_stats":null,"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/toolisticon%2FSPI-Annotation-Processor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/toolisticon%2FSPI-Annotation-Processor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/toolisticon%2FSPI-Annotation-Processor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/toolisticon%2FSPI-Annotation-Processor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/toolisticon","download_url":"https://codeload.github.com/toolisticon/SPI-Annotation-Processor/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248493501,"owners_count":21113272,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["annotation-processor","annotation-processor-toolkit","hacktoberfest","java","service","services","spi","spi-annotation-processor"],"created_at":"2024-11-14T21:21:44.763Z","updated_at":"2025-04-11T23:23:18.085Z","avatar_url":"https://github.com/toolisticon.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SPI-Annotation-Processor\n\n[![Maven Central](https://maven-badges.herokuapp.com/maven-central/io.toolisticon.spiap/spiap-processor/badge.svg)](https://maven-badges.herokuapp.com/maven-central/io.toolisticon.spiap/spiap-processor)\n[![Build Status](https://travis-ci.org/toolisticon/SPI-Annotation-Processor.svg?branch=master)](https://travis-ci.org/toolisticon/SPI-Annotation-Processor)\n[![codecov](https://codecov.io/gh/toolisticon/SPI-Annotation-Processor/branch/master/graph/badge.svg)](https://codecov.io/gh/toolisticon/SPI-Annotation-Processor)\n\n# Why you should use this project?\n\nIf you want to use a service provider interface (_SPI_) you need to register your service implementation in the _/META-INF/services/\u0026lt;Full qualified spi interface name\u0026gt;_ file.\nAdditionally, you usually need to write a service locator to be able to use the service implementation.\n\nThe annotation processor offered by this project provides exactly this. It allows you to create the service locator file just by adding an annotation to you spi implementation.\nAdditionally, it will generate a service locator for you.\n\n# Prerequisites\n- The generated ServiceLocator code requires at least JDK 8.\n\n# Features\nAnnotation processor that\n- provides support for generating service locator file in _/META-INF/services/\u0026lt;Full qualified spi interface name\u0026gt;_\n- provides support for generating service locator class for accessing the SPI implementations\n- compatible with Java \u003e= 8 (Java 7 support up to version 0.8.2)\n\n# How does it work?\n\nFirst you need to add the SPI annotation processor dependencies to your project.\n\n\t\u003cdependencies\u003e\n\t    \u003c!-- api is just needed in compile scope if you want to use the ServiceLocator features --\u003e\n\t    \u003cdependency\u003e\n\t        \u003cgroupId\u003eio.toolisticon.spiap\u003c/groupId\u003e\n\t        \u003cartifactId\u003espiap-api\u003c/artifactId\u003e\n\t    \u003c/dependency\u003e\n\t\u003c/dependencies\u003e\n\nThe annotation processor should be applied by defining it in annotation processor path of maven-compile-plugin:\n\n    \u003cplugin\u003e\n       \u003cartifactId\u003emaven-compiler-plugin\u003c/artifactId\u003e\n       \u003cconfiguration\u003e\n           \u003cannotationProcessorPaths\u003e\n               \u003cpath\u003e\n                   \u003cgroupId\u003eio.toolisticon.spiap\u003c/groupId\u003e\n                   \u003cartifactId\u003espiap-processor\u003c/artifactId\u003e\n                   \u003cversion\u003eCURRENT_VERSION\u003c/version\u003e\n               \u003c/path\u003e\n           \u003c/annotationProcessorPaths\u003e\n       \u003c/configuration\u003e\n    \u003c/plugin\u003e\n\n\n## How to generate the service locator class\n### By annotating the service provider interface\nJust add the Spi annotation to your SPI:\n\n\t@Spi\n\tpublic interface ExampleSpiInterface {\n\n\t    String doSomething();\n\n\t}\n\nThe locator is named like the SPI suffixed with ServiceLocator (ExampleSpiInterfaceServiceLocator in this example)\n\n### By annotating a package\nCreate a package-info.java file in the package were you want to create the service locator in.\nThen add the SpiServiceLocator annotation in it:\n\n    @SpiServiceLocator(ExampleSpiInterface.class)\n    package your.target.package;\n\n    import io.toolisticon.spiap.api.SpiServiceLocator;\n    import your.spi.package.ExampleSpiInterface;\n\nThe locator will be created in the annotated package. It is named like the SPI suffixed with ServiceLocator (ExampleSpiInterfaceServiceLocator in this example)\n\nTo create multiple service locators in the same package use @SpiServiceLocators:\n\n\n    @SpiServiceLocators({\n        @SpiServiceLocator(FirstExampleSpiInterface.class),\n        @SpiServiceLocator(SecondExampleSpiInterface.class)\n    })\n    package your.target.package;\n\n    import io.toolisticon.spiap.api.SpiServiceLocator;\n    import your.spi.package.FirstExampleSpiInterface;\n    import your.spi.package.SecondExampleSpiInterface;\n\n## How to register a service implementation\nJust add a Service annotation to your service implementation:\n\n\t@SpiService(value = ExampleSpiInterface.class, id = \"YOUR_OPTIONAL_SERVICE_ID\", description = \"OPTIONAL DESCRIPTION\", priority = 0)\n\tpublic class ExampleSpiService implements ExampleSpiInterface {\n\t    @Override\n            public String doSomething() {\n                return \"IT WORKS !\";\n            }\n\t}\n\nService annotations mandatory value must declare the SPI you want the service class to be registered to.\nAll other annotation attributes are optional. \n\n- id defines a custom id which can be used to locate a specific services implementation via the generated service locator class. Defaults to fully qualified service class name in generated service locator.\n- description declares a short description about the implementation\n- priority is used to define a specific order in which the services are located\n\nIt's also possible to implement more than one SPI in a class by using the Services annotation:\n        \n\t@SpiServices({\n\t    @SpiService(value = ExampleSpiInterface1.class, id = \"YOUR_OPTIONAL_SERVICE_ID\", description = \"OPTIONAL DESCRIPTION\", priority = 0),\n\t    @SpiService(value = ExampleSpiInterface2.class)\n\t})\n\tpublic class ExampleSpiService implements ExampleSpiInterface1, ExampeSpiInterface2 {\n\t    @Override\n            public String doSomething1() {\n                return \"IT WORKS !\";\n            }\n\t    @Override\n            public String doSomething2() {\n                return \"IT WORKS TOO!\";\n            }\n\t}\n\n## How to use the service locator\n\n\tSystem.out.println(ExampleSpiInterfaceServiceLocator.locate().doSomething());\n\n\nIt's not required to have the spiap-api dependency at runtime anymore since settings of annotations will be stored in a generated property file (stored in /META-INF/spiap/\u0026lt;service interface fqn\u0026gt;/\u0026lt;service implementation fqn\u0026gt;.properties).\nSee our examples subprojects for further information.\n\n## Disable service implementations in the service locator\nJust add the _OutOfService_ annotation next to the Services or Service annotation to disable the service implementation in the service locator.\n\n# Contributing\n\nWe welcome any kind of suggestions and pull requests.\n\n## Building and developing the SPI-Annotation-Processor\n\nThe SPI-Annotation-Processor is built using Maven (at least version 3.0.0).\nA simple import of the pom in your IDE should get you up and running. To build the annotation-processor-toolkit on the commandline, just run `mvn` or `mvn clean install`\n\n## Requirements\n\nThe likelihood of a pull request being used rises with the following properties:\n\n- You have used a feature branch.\n- You have included a test that demonstrates the functionality added or fixed.\n- You adhered to the [code conventions](http://www.oracle.com/technetwork/java/javase/documentation/codeconvtoc-136057.html).\n\n## Contributions\n\n- (2017) Tobias Stamann (Holisticon AG)\n\n# License\n\nThis project is released under the revised [MIT License](LICENSE).\n\nThis project includes and repackages the [Annotation-Processor-Toolkit](https://github.com/holisticon/annotation-processor-toolkit) released under the  [MIT License](/3rdPartyLicenses/annotation-processor-toolkit/LICENSE.txt).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftoolisticon%2Fspi-annotation-processor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftoolisticon%2Fspi-annotation-processor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftoolisticon%2Fspi-annotation-processor/lists"}