Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider integration of openrewrite #991

Closed
hohwille opened this issue Nov 23, 2022 · 7 comments · Fixed by #1047
Closed

Consider integration of openrewrite #991

hohwille opened this issue Nov 23, 2022 · 7 comments · Fixed by #1047
Assignees
Labels
enhancement New feature or request migator related to devon4j project migrator feature (devon java migrate ...) setup related to the setup process of devonfw-ide (setup[.bat] and devon ... setup)

Comments

@hohwille
Copy link
Member

hohwille commented Nov 23, 2022

The tool openrewrite allows to define "recepies" that are a description of a migration and supports applying them to a project.
This allows to automate migrations in code projects.
The ecosystem of openrewrite already offers all kind of migrations for spring and spring boot but also for maven, kuberenetes, etc.

This could entirely replace our custom build migrations (see devon java migrate).
See also issue #226 (PR #597).

In the future we could offer migrations like e.g. devon rewrite «recepie».

@hohwille hohwille added enhancement New feature or request migator related to devon4j project migrator feature (devon java migrate ...) setup related to the setup process of devonfw-ide (setup[.bat] and devon ... setup) Team_IDE labels Nov 23, 2022
@alfeilex
Copy link
Member

alfeilex commented Dec 15, 2022

My first assumption that we need to change the pom.xml to run the rewrite-maven-plugin was wrong. We can use a single command to run built-in recepies.

For example:
./mvnw org.openrewrite.maven:rewrite-maven-plugin:4.38.0:run -Drewrite.activeRecipes=org.openrewrite.java.format.AutoFormat

For external recepies we need to add dependencies. I am not aware how to add dependencies with mvn command. If that is possible we can wrap the whole command with some parameters.

See here for more information about running recepies with openrewrite:
https://docs.openrewrite.org/getting-started/getting-started

@alfeilex
Copy link
Member

After testing some ideas for integratiing openrewrite into ide, I found that we can define the location of the pom.xml, which contains the dependencies for the recipe-plugin with -f.

Finally, we can use devon rewrite <recipe-name> as a wrapper for devon maven org.openrewrite.maven:rewrite-maven-plugin:4.38.0:run -Drewrite.activeRecipes=<recipe-name> -f <path-pom> and run external recipes.

@alfeilex
Copy link
Member

Some recipes are more complex and need a yaml file with configuration. See here. A possible structure for all files needed for rewrite plugin could look like this:

conf/
--rewrite/
----pom.xml
----rewrite.yaml

@alfeilex
Copy link
Member

alfeilex commented Dec 27, 2022

Questions left open after researching how to integrate rewrite into the devon ide:

  • Do we offer all the extended recipes offered by open-rewrite (See here)?
  • Do we add a new command rewrite ? It is not a CLI and has not setup like previous commandlets.
  • Or do we extend the maven commandlet?

After these points are discussed, we can continue with the issue.

@alfeilex
Copy link
Member

alfeilex commented Jan 5, 2023

I don't think that we can integrate open-rewrite in the current manner of devon-ide. While built-in recipes can be run with
devon maven org.openrewrite.maven:rewrite-maven-plugin:4.38.0:run -Drewrite.activeRecipes=<recipe-name>
there are recipes for which plugin dependencies must be set in pom.xml file of the target project.

For example:

<build>
    <plugins>
        <plugin>
            <groupId>org.openrewrite.maven</groupId>
            <artifactId>rewrite-maven-plugin</artifactId>
            <version>4.38.0</version>
            <dependencies>
            <dependency>
                <groupId>org.openrewrite.recipe</groupId>
                <artifactId>rewrite-spring</artifactId>
                <version>4.28.0</version>
            </dependency>
            </dependencies>
        </plugin>
    </plugins>
  </build>

The rewrite-spring dependency provides more spring related recipes but it has to be added as a dependency in the pom.xml. I have not find a workaround to make plugin-dependencies work without the pom.xml. Maybe there is a way I don't know about, but I spent hours in the Maven documentation and could not find any useful information.

@alfeilex
Copy link
Member

The solution of adding the plugin dependencies in settings.xml does not work because it is not possible to add <build> tag in the settings.xml.

Finally, the cost-benefit ratio is not worth it in my opinion to integrate the tool into the IDE.

@alfeilex
Copy link
Member

As long as there is no "simple" solution (handling plugin dependencies in pom.xml) to integrate this tool into the IDE, we should save this issue for future tasks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request migator related to devon4j project migrator feature (devon java migrate ...) setup related to the setup process of devonfw-ide (setup[.bat] and devon ... setup)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants