openrewrite / rewrite-docs

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

missing jspecify dependency in refaster recipes documentation #297

Closed Bananeweizen closed 1 month ago

Bananeweizen commented 1 month ago

The main repo recently added jspecify: https://github.com/openrewrite/rewrite/pull/4418. That leads to transitive dependencies. Creating a custom template based recipe following https://docs.openrewrite.org/authoring-recipes/refaster-recipes therefore fails with compile errors for the generated code, specifically the places using the jspecify annotations.

What is the smallest, simplest way to reproduce the problem?

Just have a pom.xml with the contents from https://docs.openrewrite.org/authoring-recipes/refaster-recipes and a trivial recipe.

What is the full stack trace of any errors you encountered?

Compilation failure:
[ERROR] FooRecipes.java:[3,32] package org.jspecify.annotations does not exist
[ERROR] FooRecipes.java:[54,6] cannot find symbol
[ERROR]   symbol:   class NullMarked

To fix this, it's sufficient to add

        <dependency>
            <groupId>org.jspecify</groupId>
            <artifactId>jspecify</artifactId>
            <version>1.0.0</version>
        </dependency>

Are you interested in contributing a fix to OpenRewrite?

No. I'm not sure whether the documentation should be updated to just include that dependency (for both gradle and maven builds), or whether something can be done to explicitly re-export the dependency already from the rewrite core module.

Side note: If the documentation is going to be updated, then you may want to think about removing the lombok annotation processor from the same page. It's not needed AFAIK.

timtebeek commented 1 month ago

The next release of openrewrite/rewrite will see rewrite-core bring in jspecify transitively; we figured that would be easiest, but still need to do that likely patch release somewhere this week. That would then also remove the need to add jspecify to the docs.

I'm not seeing lombok referenced on the page you linked above. Did I miss anything?

timtebeek commented 1 month ago

We just released a new version of OpenRewrite which should have solved this issue already:

Since I'm not seeing any lombok references I'm going to proactively close this issue. If I missed anything let me know!

Bananeweizen commented 1 month ago

@timtebeek Thanks, I'm always surprised by how fast this projects reacts and releases new versions.

The lombok annotation processor is referenced here: https://github.com/openrewrite/rewrite-docs/blob/93527d3670b516c350faca901de7a0011e9e1cd2/authoring-recipes/refaster-recipes.md?plain=1#L136-L140 (that's the maven tab of https://docs.openrewrite.org/authoring-recipes/refaster-recipes). So the situation is

I'm not exactly sure what to make of that, but you may want to make it consistent, one way or another. :)

timtebeek commented 1 month ago

Ah that makes sense why I didn't find it initially with a quick search, thanks! I think it might be best to keep it there, as we do recommend lombok for @Value annotations on our recipes elsewhere, and we'll want folks not to see that break when adding the refaster template processor. In isolation it's true that it's not necessary for Maven; in practice I think it'll likely end up being used anyway.

For Gradle there's less of a need to list lombok, as there's no need to edit the same maven compiler plugin configuration block if lombok were to be added to a Gradle project already using our refaster support.