openrewrite / rewrite-docs

Stores the markdown documents used to generate docs.openrewrite.org
https://docs.openrewrite.org
Apache License 2.0
39 stars 42 forks source link

Add reference to `-parameters` somewhere #185

Open nmck257 opened 1 year ago

nmck257 commented 1 year ago

I was working with someone recently who was getting started with recipe development, using a Maven project.

When trying to run their SayHello recipe, they ran into the cryptic recipe-deserialization issue which the -parameters option solves (eg https://github.com/moderneinc/rewrite-recipe-starter/blob/main/build.gradle.kts#L82)

Sample error message:

Recipe validation error in com.mycompany.MyRecipe: Unable to load Recipe: java.lang.IllegalArgumentException: Invalid type definition for type com.mycompany.MyRecipe: Argument #0 of constructor [constructor for com.mycompany.MyRecipe (7 args), annotations: {interface com.fasterxml.jackson.annotation.JsonCreator=@com.fasterxml.jackson.annotation.JsonCreator(mode=DEFAULT)} has no property name (and is not Injectable): can not use as property-based Creator at [Source: UNKNOWN; byte offset: #UNKNOWN]`

The option is already included in the Gradle rewrite-recipe-starter, but if a beginner deviates at all and runs into that error, then it's pretty difficult to troubleshoot. I think it's worth writing down somewhere.

knutwannheden commented 1 year ago

Good call. Possibly the RecipeTest infrastructure could provide this hint.

mike-solomon commented 12 months ago

@knutwannheden Do you think this should be moved to rewrite instead? I may be misunderstanding, but your comment makes it sound like this is something we should change in rewrite itself rather than in the docs.

If this is something we want to add to the docs, does anyone have thoughts on where to add this? Also, could anyone provide me with more context on this if that's the case? Is the issue that people see an error message that contains something like no property name and then they need to update their build.gradle file to include a parameters flag or something? How does that help and what is that doing?

Thanks!

pukkaone commented 3 weeks ago

Developers who follow the documentation's suggested path of using the rewrite-recipe-starter repository as a template for their recipe project are fortunate to start with a Maven project that turns on the -parameters option of the Java compiler . This option is necessary for OpenRewrite to deserialize recipes.

However, developers who follow the documentation's manual project setup path will encounter this deserialization error. The example Maven build file does NOT turn on the -parameters option. The documentation does not mention that this option must be turned on.