I have searched the documentation and StackOverflow and never found any details about how the recipes of OpenRewrite are applied to different files. Is the first recipe applied to all files or are all recipes applied to the first file first?
According to my testing, it seems to be the second case. Which is problematic become some recipes rely on changes to other files, e.g. adding a maven dependency to the POM if that dependency is now used due to another recipe.
Example: Migrating hamcrest to AssertJ with org.openrewrite.java.testing.hamcrest.MigrateHamcrestToAssertJ
The recipe list contains a recipe to add the AssertJ dependency if it is used in the project. My project didn't contain AssertJ before applying the migration script.
The expectation would be that running the recipe would also add the AssertJ dependency, but it does not - on the first run. If I execute it again, the dependency is added.
To not rely of the internal recipe order in the linked recipe, I also tried to add another AddDependency recipe to be executed after the AssertJ migration. Same behaviour.
My project is multi-module, but I could reproduce the issue on a simple Maven project.
Am I missing something or is there some solution to this problem?
Edit: Just found out that the recipe for the JUnit migration will already add the JUnit5 dependency if usage of JUnit4 is detected. Is that the only workaround? https://docs.openrewrite.org/recipes/java/testing/junit5/junit4to5migration