Modifications to maven utilities ListDependencies and new utility recipes for managing dependencies(Willing to contribute)
Hello,
Found this project through a talk, and it is fascinating to see all the work you guys did!
We have a requirement for our project that we need to be able to do couple of things with with pom files:
-List all the direct dependencies -Fetch the newest released versions of these dependencies(a different recipe) -Upgrade the dependencies to their latest versions(another recipe)
I was going to fork the project, but since these requirements are needed by a lot of people, I first decided to ask whether if you would accept a PR or not.
I was going to ask would you accept a PR to do:
-Add a parameter to maven utilities ListDependencies to list only direct dependencies. -Add a new scope to scope parameter called "all" to list all dependencies.(I don't know how to implement that properly though) -Add a recipe for listing upgrades for direct dependencies(including parent and plug-ins) -Add a new recipe for upgrading the said direct dependencies.
I haven't contributed any code to open source so I have very limited knowledge of how the contributions work 🙂
I am open to discussing the requirements and any changes that you would suggest.
Hi @fatihdogmus, welcome to openrewrite! @tkvangorder is best suited to answer your questions and is very busy, but I'm sure he'll answer asap!
@fatihdogmus Welcome!
These changes would be very useful and we can help you if you have any questions. You will find we are a friendly bunch.
- [ ] Adding a parameter to the ListDependencies recipe to only include direct dependencies
In Rewrite, a pom is represented as an XML document that also has a marker on it called MavenResolutionResult. The marker represents all the semantic information about the Maven build whereas the document is strictly representing the XML for that pom. You can always get to the semantic information, by extracting this marker from the top-level SourceFile, and if you look at the MavenVisitor we have a helper that does just that.
Once you have the MavenResolutionResult, you have access to the "resolved" pom (basically think of this as the final view of the pom, after we have considered its parent, collected properties, resolved dependencies, dependency management, etc. And inside that resolved pom, you will also find "requestedPom" The requested Pom, is what the pom looked like BEFORE we did any resolution, so it is the requested pom that can be used to find the direct dependencies. Note, the version in the requested may not match what was resolved and this can take some time to get your head wrapped around. But what you can do, is grab the artifact/group from the requested dependency and then consult the MavenResolutionResult to find what the resolved version is.
- [ ] Adding a new scope "all"
I think rather than adding an "all" scope, I would treat the absence of scope to mean "all". So if you have a ListDependencies with an optional scope parameter, if that parameter is not provided, assume all.
- [ ] Add a recipe for upgrading all direct dependencies.
This is actually going to be easy, once you have a utility to list all direct dependencies. We already provide a recipe to upgrade a dependency.
The nice thing about this recipe is it allows you to specify the new version as a semantic version selector: 3.1.x, 2.x, etc This recipe will already look for the most current version and change it appropriately. So, all your recipe would need to do is iterate over the list of direct dependencies and schedule an update dependency for each one.
I think if you start with modifying the ListDependenices, this would be a great place to start and we can help you if you have any questions related to the work or submitting the PR.
Looking forward to working with you!
Ok thank you very much! I'll talk with my team lead and start ASAP. Our timelines are bit tight right now, but I will try to start ASAP.