rewrite icon indicating copy to clipboard operation
rewrite copied to clipboard

Recipes for maven wrapper

Open yeikel opened this issue 2 years ago • 6 comments

It would be nice to have recipes for

  1. Add maven wrapper
  2. Update maven wrapper to a specific version

Note :

  • distributionUrl and wrapperUrl should be customizable for corporate environments

See : https://maven.apache.org/wrapper/

yeikel avatar Apr 04 '22 21:04 yeikel

@tkvangorder Should we have separate issues for this?

yeikel avatar Apr 04 '22 21:04 yeikel

I think this work will be similar to https://github.com/openrewrite/rewrite/issues/1542

I would suggest that the takari/maven-wrapper migration be made a separate task.

tkvangorder avatar Apr 04 '22 21:04 tkvangorder

I think this work will be similar to #1542

I would suggest that the takari/maven-wrapper migration be made a separate task.

Thank you. I created https://github.com/openrewrite/rewrite/issues/1566

yeikel avatar Apr 04 '22 21:04 yeikel

I tested this internally and maven was smart enough to figure out the distributionUrl and wrapperUrl automatically using my .m2 settings

The issue I found is that it did not find the latest(3.8.5 at the time of this writing) and it defaulted to 3.8.4 instead. It could also be because the latest version of the wrapper was released before 3.8.5

Running it with the specific version fixed it : mvn wrapper:wrapper -Dmaven=3.8.5

yeikel avatar Apr 05 '22 00:04 yeikel

Would be good to also clean up MavenWrapperDownloader.java, as that get's left behind otherwise.

timtebeek avatar May 21 '22 20:05 timtebeek

Had a quick look through the Apache Maven Wrapper Mojo for inspiration, as that already downloads, unpacks & replaces properties, in addition to removing Takari wrapper files.

Would you recon we can declare a dependency on org.apache.maven.plugins:maven-wrapper-plugin and write a recipe that invokes WrapperMojo#execute()? There's some stuff to figure out still then like the @Parameter/@Inject annotated fields, but it might be preferable to reuse as much as possible.

Otherwise we can copy the ~200 or so lines in WrapperMojo, and only depend on org.apache.maven.plugins:maven-wrapper as a next best option.

What are your thoughts on the above? While the Apache Maven Wrapper plugin works as is, it would be nice to apply this in bulk through OpenRewrite, especially when it's a necessary step for other migration recipes such as a Java 17 migration.

timtebeek avatar Aug 24 '22 18:08 timtebeek

As part of this recipe, we should make the wrapper executable:

 chmod +x mvnw

Otherwise, some CI environments (like GH actions), will throw this:

./mvnw: Permission denied

We can use org.openrewrite.SetFilePermissions for this

yeikel avatar Mar 07 '23 17:03 yeikel