rewrite-docs icon indicating copy to clipboard operation
rewrite-docs copied to clipboard

Add reference to `-parameters` somewhere

Open nmck257 opened this issue 1 year ago • 3 comments

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.

nmck257 avatar Jun 23 '23 12:06 nmck257

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

knutwannheden avatar Jun 23 '23 12:06 knutwannheden

@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!

mike-solomon avatar Aug 01 '23 18:08 mike-solomon

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.

pukkaone avatar Jul 07 '24 08:07 pukkaone