Skip to content

Commit 63889ad

Browse files
authored
Explain using jakarta.annotation.Generated for refaster recipes (#361)
* Explain using jakarta.annotation.Generated for refaster recipes * Exclude Arewrite from spell checking * Exclude Arewrite from spell checking
1 parent cd7737b commit 63889ad

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

.github/actions/spelling/allow.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ https
44
ssh
55
ubuntu
66
workarounds
7+
Arewrite

docs/authoring-recipes/refaster-recipes.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,55 @@ dependencies {
167167
</TabItem>
168168
</Tabs>
169169

170+
### Compiling with Java 9 or higher
170171

172+
The annotation processor used to generate the Refaster template recipe implementation will automatically add an annotation of type `javax.annotation.Generated`. This annotation was removed from the JDK in Java 9.
173+
174+
If your project uses Java 9 or higher, you will need to add the dependency `jakarta.annotation:jakarta.annotation-api:3.0.0` to the compilation classpath. The dependency contributes the `jakarta.annotation.Generated` annotation which is the replacement for the `javax.annotation.Generated` class. In addition, you will need to provide the flag `-Arewrite.generatedAnnotation=jakarta.annotation.Generated` to the Java compiler.
175+
176+
<Tabs groupId="projectType">
177+
<TabItem value="gradle" label="Gradle">
178+
179+
```groovy title="build.gradle"
180+
dependencies {
181+
implementation("jakarta.annotation:jakarta.annotation-api:3.0.0")
182+
}
183+
184+
tasks.named("compileJava", JavaCompile).configure {
185+
options.compilerArgs.add("-Arewrite.generatedAnnotation=jakarta.annotation.Generated")
186+
}
187+
```
188+
189+
</TabItem>
190+
191+
<TabItem value="maven" label="Maven">
192+
193+
```xml title="pom.xml"
194+
<dependencies>
195+
<dependency>
196+
<groupId>jakarta.annotation</groupId>
197+
<artifactId>jakarta.annotation-api</artifactId>
198+
<version>3.0.0</version>
199+
</dependency>
200+
</dependencies>
201+
202+
<build>
203+
<plugins>
204+
<plugin>
205+
<groupId>org.apache.maven.plugins</groupId>
206+
<artifactId>maven-compiler-plugin</artifactId>
207+
<configuration>
208+
<compilerArgs>
209+
<arg>-Arewrite.generatedAnnotation=jakarta.annotation.Generated</arg>
210+
</compilerArgs>
211+
</configuration>
212+
</plugin>
213+
</plugins>
214+
</build>
215+
```
216+
217+
</TabItem>
218+
</Tabs>
171219

172220
### Create a Java class
173221

0 commit comments

Comments
 (0)