aboutsummaryrefslogtreecommitdiff
path: root/service
diff options
context:
space:
mode:
authorcpovirk <cpovirk@google.com>2019-10-06 00:16:58 -0700
committerNick Glorioso <nick@nickglorioso.com>2019-10-08 09:35:52 -0400
commit7b0ce2dbed242dc55d2916db24cc2ac8761578e4 (patch)
treea5720a3e2d87497588d9226d9320e2f23da941ef /service
parentdb3fc6d39e1d7dc11505efefe67453407ffcc970 (diff)
downloadauto-7b0ce2dbed242dc55d2916db24cc2ac8761578e4.tar.gz
Document the annotationProcessorPaths approach to using AutoService.
We've already documented this for AutoValue: https://github.com/google/auto/blob/master/value/userguide/index.md#in-pomxml Here, I've chosen to recommend annotationProcessorPaths as the first option: - I assume that this reduces the chance of classpath conflicts. - It also keeps AutoService working when I switch to the new way of running Error Prone (though maybe there are alternatives). See CL 272720556. Also, run the whole file through mdformat. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=273124744
Diffstat (limited to 'service')
-rw-r--r--service/README.md83
1 files changed, 57 insertions, 26 deletions
diff --git a/service/README.md b/service/README.md
index f9455bdf..dd9251fa 100644
--- a/service/README.md
+++ b/service/README.md
@@ -1,19 +1,19 @@
-AutoService
-======
+# AutoService
-A configuration/metadata generator for java.util.ServiceLoader-style service providers
+A configuration/metadata generator for java.util.ServiceLoader-style service
+providers
-AutoWhat‽
----------
+## AutoWhat‽
-[Java][java] annotation processors and other systems use [java.util.ServiceLoader][sl] to
-register implementations of well-known types using META-INF metadata. However, it is easy
-for a developer to forget to update or correctly specify the service descriptors.
-AutoService generates this metadata for the developer, for any class annotated with
-`@AutoService`, avoiding typos, providing resistance to errors from refactoring, etc.
+[Java][java] annotation processors and other systems use
+[java.util.ServiceLoader][sl] to register implementations of well-known types
+using META-INF metadata. However, it is easy for a developer to forget to update
+or correctly specify the service descriptors. \
+AutoService generates this metadata for the developer, for any class annotated
+with `@AutoService`, avoiding typos, providing resistance to errors from
+refactoring, etc.
-Example
--------
+## Example
Say you have:
@@ -28,26 +28,58 @@ final class MyProcessor implements Processor {
}
```
-AutoService will generate the file `META-INF/services/javax.annotation.processing.Processor`
-in the output classes folder. The file will contain:
+AutoService will generate the file
+`META-INF/services/javax.annotation.processing.Processor` in the output classes
+folder. The file will contain:
```
foo.bar.MyProcessor
```
-In the case of javax.annotation.processing.Processor, if this metadata file is included in a jar,
-and that jar is on javac's classpath, then `javac` will automatically load it, and include it in
-its normal annotation processing environment. Other users of java.util.ServiceLoader may use
-the infrastructure to different ends, but this metadata will provide auto-loading appropriately.
+In the case of javax.annotation.processing.Processor, if this metadata file is
+included in a jar, and that jar is on javac's classpath, then `javac` will
+automatically load it, and include it in its normal annotation processing
+environment. Other users of java.util.ServiceLoader may use the infrastructure
+to different ends, but this metadata will provide auto-loading appropriately.
-Download
---------
+## Getting Started
-In order to activate metadata generation you will need to include
-`auto-service-${version}.jar` in your build at compile time.
+You will need `auto-service-annotations-${version}.jar` in your compile-time
+classpath, and you will need `auto-service-${version}.jar` in your
+annotation-processor classpath.
-In a Maven project, one would include the `auto-service`
-artifact as an "optional" dependency:
+In Maven, you can write:
+
+```xml
+<dependencies>
+ <dependency>
+ <groupId>com.google.auto.service</groupId>
+ <artifactId>auto-service-annotations</artifactId>
+ <version>${auto-service.version}</version>
+ <optional>true</optional>
+ </dependency>
+</dependencies>
+
+...
+
+<plugins>
+ <plugin>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <annotationProcessorPaths>
+ <path>
+ <groupId>com.google.auto.service</groupId>
+ <artifactId>auto-service</artifactId>
+ <version>${auto-service.version}</version>
+ </path>
+ </annotationProcessorPaths>
+ </configuration>
+ </plugin>
+</plugins>
+```
+
+Alternatively, you can include the processor itself (which transitively depends
+on the annotation) in your compile-time classpath:
```xml
<dependencies>
@@ -60,8 +92,7 @@ artifact as an "optional" dependency:
</dependencies>
```
-License
--------
+## License
Copyright 2013 Google LLC