rewrite
rewrite copied to clipboard
Recipes for maven wrapper
It would be nice to have recipes for
- Add maven wrapper
- Update maven wrapper to a specific version
Note :
-
distributionUrl
andwrapperUrl
should be customizable for corporate environments
See : https://maven.apache.org/wrapper/
@tkvangorder Should we have separate issues for this?
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.
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
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
Would be good to also clean up MavenWrapperDownloader.java, as that get's left behind otherwise.
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.
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