Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Separate auto-factory compiler and annotations #1814

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 37 additions & 7 deletions factory/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,45 @@ final class SomeClass {
}
```

Download
--------

In order to activate code generation you will need to
include `auto-factory-${version}.jar` in your build at
compile time.
## Getting Started

In a Maven project, one would include the `auto-factory`
artifact as an "optional" dependency:
You will need `auto-factory-annotations-${version}.jar` in your compile-time
classpath, and you will need `auto-factory-${version}.jar` in your
annotation-processor classpath.

In Maven, you can write:

```xml
<dependencies>
<dependency>
<groupId>com.google.auto.factory</groupId>
<artifactId>auto-factory-annotations</artifactId>
<version>${auto-factory.version}</version>
</dependency>
</dependencies>

...

<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>com.google.auto.factory</groupId>
<artifactId>auto-factory</artifactId>
<version>${auto-factory.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. (However, note that doing so
may pull unnecessary classes into your runtime classpath.)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see that this matches https://github.com/google/auto/blob/main/value/userguide/index.md#with-maven, so that's fine for this PR. I'm just noting for the record that we should probably revisit both in the future.

My reasoning: This approach will also not work if you already have something else in annotationProcessorPaths, and it won't work in upcoming JDKs unless you pass more flags (It's possible that Maven specifically will pass those options if it doesn't already, but I also note that Gradle has been pushing users away from the classpath approach, too.)


```xml
<dependencies>
Expand Down
66 changes: 66 additions & 0 deletions factory/annotations/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright 2013 Google LLC

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>com.google.auto.factory</groupId>
<artifactId>auto-factory-aggregator</artifactId>
<version>HEAD-SNAPSHOT</version>
</parent>

<groupId>com.google.auto.factory</groupId>
<artifactId>auto-factory-annotations</artifactId>
<version>HEAD-SNAPSHOT</version>
<name>AutoFactory Annotations</name>
<description>
JSR-330-compatible factories.
</description>
<url>https://github.com/google/auto/tree/main/factory</url>

<scm>
<url>http://github.com/google/auto</url>
<connection>scm:git:git://github.com/google/auto.git</connection>
<developerConnection>scm:git:ssh://[email protected]/google/auto.git</developerConnection>
<tag>HEAD</tag>
</scm>

<build>
<plugins>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifestEntries>
<Automatic-Module-Name>com.google.auto.factory</Automatic-Module-Name>
</manifestEntries>
</archive>
</configuration>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<!-- disable processing because the definition in META-INF/services breaks javac -->
<compilerArgument>-proc:none</compilerArgument>
<source>1.8</source>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need source and target here, or do we inherit them from the aggregator parent pom? If we need them, maybe we can still use java.version?

<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
Loading