Skip to content

Commit e194617

Browse files
bmuschkotimtebeekmike-solomon
authored
Explain compiler options needed for Jackson deserialization (#381)
* Explain compiler options needed for Jackson deserialization * Update docs/authoring-recipes/recipe-development-environment.md Co-authored-by: Tim te Beek <timtebeek@gmail.com> * Update docs/authoring-recipes/recipe-development-environment.md --------- Co-authored-by: Tim te Beek <timtebeek@gmail.com> Co-authored-by: Mike Solomon <mikesol@hey.com>
1 parent 8e6ab1b commit e194617

File tree

1 file changed

+42
-9
lines changed

1 file changed

+42
-9
lines changed

docs/authoring-recipes/recipe-development-environment.md

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ mvn -B archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-app -Darch
5555
</TabItem>
5656
</Tabs>
5757

58+
:::tip
59+
If you are using Gradle, it is highly-recommended that you apply the [`org.openrewrite.build.recipe-library-base` plugin](https://plugins.gradle.org/plugin/org.openrewrite.build.recipe-library-base). The plugin automatically configures the project with meaningful conventions like necessary compiler options.
60+
:::
61+
5862
### Dependencies & dependency management
5963

6064
Rewrite provides a bill of materials (BOM) that, when imported into your build, will manage the versions of any rewrite dependencies that are included within a project.
@@ -108,11 +112,7 @@ dependencies {
108112

109113
```xml title="pom.xml"
110114
<properties>
111-
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
112-
<maven.compiler.source>1.8</maven.compiler.source>
113-
<maven.compiler.target>1.8</maven.compiler.target>
114-
<maven.compiler.testSource>17</maven.compiler.testSource>
115-
<maven.compiler.testTarget>17</maven.compiler.testTarget>
115+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
116116
</properties>
117117

118118
<dependencyManagement>
@@ -219,10 +219,6 @@ dependencies {
219219
<artifactId>maven-compiler-plugin</artifactId>
220220
<version>3.13.0</version>
221221
<configuration>
222-
<!-- Jackson deserialization requires named parameters -->
223-
<compilerArgs>
224-
<arg>-parameters</arg>
225-
</compilerArgs>
226222
<!-- lombok is optional, but recommended for authoring recipes -->
227223
<annotationProcessorPaths>
228224
<path>
@@ -283,6 +279,43 @@ tasks.compileJava {
283279
</TabItem>
284280
</Tabs>
285281

282+
### Jackson deserialization
283+
284+
Some recipe implementations may use [Jackson deserialization](https://github.com/FasterXML/jackson-annotations) by defining annotations such as `@JsonCreator` and `@JsonProperty`.
285+
286+
In order to deserialize Java classes, you need to add the `-parameters` compiler argument. This is necessary for Jackson to be able to deserialize the constructor parameters of a class.
287+
288+
<Tabs groupId="projectType">
289+
<TabItem value="gradle" label="Gradle">
290+
291+
```groovy title="build.gradle"
292+
tasks.withType(JavaCompile).configureEach {
293+
options.compilerArgs.add('-parameters')
294+
}
295+
```
296+
</TabItem>
297+
298+
<TabItem value="maven" label="Maven">
299+
300+
```xml title="pom.xml"
301+
<build>
302+
<plugins>
303+
<plugin>
304+
<groupId>org.apache.maven.plugins</groupId>
305+
<artifactId>maven-compiler-plugin</artifactId>
306+
<version>3.14.0</version>
307+
<configuration>
308+
<compilerArgs>
309+
<arg>-parameters</arg>
310+
</compilerArgs>
311+
</configuration>
312+
</plugin>
313+
</plugins>
314+
</build>
315+
```
316+
</TabItem>
317+
</Tabs>
318+
286319
### Project layout
287320

288321
Having configured the project per these recommendations, you're now able to begin Recipe development. With Gradle and Maven's default project layout, you'll want to put your files in these directories:

0 commit comments

Comments
 (0)