Skip to content

Remove standard maven-compiler plugin for applications with boot parent #428

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

Open
fabapp2 opened this issue Sep 20, 2022 · 6 comments
Open
Assignees
Labels

Comments

@fabapp2
Copy link
Contributor

fabapp2 commented Sep 20, 2022

What needs to be done

Provide a recipe remove-redundant-maven-compiler-plugin that removes redundant maven-compiler-plugin configurations in Spring Boot applications that have a spring-boot parent where the compiler-plugin is managed.

Why it needs to be done

Cleaner pom.xml by using Spring Boot's plugin management

Acceptance Criteria

Given: A pom.xml with direct or indirect spring-boot-starter-parent and a standard maven-compiler-plugin configuration with only source and target
When: remove-redundant-maven-compiler-plugin is applied
Then: The maven-compiler-plugin is removed and Properties defining the java version are replaced with java.version property used by boot.

Additional Information

@fabapp2 fabapp2 added the Recipe label Sep 20, 2022
@ahmedmq
Copy link
Contributor

ahmedmq commented Oct 6, 2022

@fabapp2 - would like to try creating a new recipe. Maybe I can pick this one to get started?

@fabapp2
Copy link
Contributor Author

fabapp2 commented Oct 7, 2022

Great, thanks! 🚀
Happily assigned-to: @ahmedmq

@fabapp2
Copy link
Contributor Author

fabapp2 commented Oct 7, 2022

The description is rather minimal, don't hesitate to pull all information you need.

@ahmedmq
Copy link
Contributor

ahmedmq commented Oct 10, 2022

Hey @fabapp2 : Just wanted to share my understanding of the changes required . Could you let me know of anything i have missed

Recipe:
Create new recipe using YML configuration possibly under sbm-support-boot module

Conditions:

  • Check if the spring boot parent has been declared using the existing HasDecalredSpringBootStarterParent
  • New SBM condition to be created to check if maven-compiler-plugin exists with only source and target under configuration

Action:

  • Remove maven-compiler-plugin plugin using RemovePluginsMatchingRegex

Also, I was not sure about replacing the Java properties and what is to be done. Spring boot parent already defines these properties:

  <java.version>1.8</java.version>
  <maven.compiler.source>${java.version}</maven.compiler.source>
  <maven.compiler.target>${java.version}</maven.compiler.target>

@fabapp2
Copy link
Contributor Author

fabapp2 commented Oct 11, 2022

Hi @ahmedmq, thanks for your analysis!

Your observations are all correct for my understanding.

I can see the recipe doing two things:

. Always clean up properties
. When no additional configuration is provided, remove the plugin

Clean up properties

  • When target and source version differ, do nothing

Otherwise

  • maven.compiler.source and maven.compiler.target should be retrieved from parent
  • The version should be set using java.version
  • Custom property for version in maven-compiler-plugin should be replaced with maven.compiler.*
    • All other usages of the custom property should to be replaced with java.version
  • Fixed values for target and version should be replaced with maven.compiler.* properties set through java.version

gh428

PlatUML code: gh428.puml.txt

Removing the plugin

  • After cleaning up the properties
  • When the plugin has no additional configuration, remove it

It's probably a good idea to have two Actions, one cleaning up the properties and one actually removing the plugin.
This would allow us to use them separately (in two recipes) when needed.

Your thoughts on this?

@ahmedmq
Copy link
Contributor

ahmedmq commented Oct 12, 2022

I think i get it. Let me start and I will reach out if I get stuck

fabapp2 added a commit to ahmedmq/spring-boot-migrator that referenced this issue Oct 31, 2022
fabapp2 added a commit to ahmedmq/spring-boot-migrator that referenced this issue Nov 2, 2022
fabapp2 pushed a commit that referenced this issue Dec 15, 2022
…nt - gh-428 (#508)

- Add New recipe and condition
- Enhance PomBuilder.java
- Use MavenBuildFileRefactoring to apply recipe, similar to JavaRefactoring
- Refactor getPlugins() method in OpenRewriteMavenBuildFile
- Extract Plugin interface and refactor Maven Plugin implementation
- Create new interface `Plugin#Configuration` and implementation
- Refactor `Plugin#Execution` into `OpenRewriteMavenPlugin#OpenRewriteMavenPluginExecution`
- Add deleteProperty() API to BuildFile
- setProperty() API no longer removes the maven property if the value supplied is null.
- Add maven plugin configuration to PomBuilder
- Use Jackson XML pretty print to generate XML string for plugin configuration
- Add findPlugins API to BuildFile
- Use Plugin interface instead of OpenRewriteMavenPlugin implementation in dealing with objects
- Refactor Maven compiler plugin actions
- Clean up BuildFile API
fabapp2 pushed a commit that referenced this issue Jan 31, 2023
…nt - gh-428 (#508)

- Add New recipe and condition
- Enhance PomBuilder.java
- Use MavenBuildFileRefactoring to apply recipe, similar to JavaRefactoring
- Refactor getPlugins() method in OpenRewriteMavenBuildFile
- Extract Plugin interface and refactor Maven Plugin implementation
- Create new interface `Plugin#Configuration` and implementation
- Refactor `Plugin#Execution` into `OpenRewriteMavenPlugin#OpenRewriteMavenPluginExecution`
- Add deleteProperty() API to BuildFile
- setProperty() API no longer removes the maven property if the value supplied is null.
- Add maven plugin configuration to PomBuilder
- Use Jackson XML pretty print to generate XML string for plugin configuration
- Add findPlugins API to BuildFile
- Use Plugin interface instead of OpenRewriteMavenPlugin implementation in dealing with objects
- Refactor Maven compiler plugin actions
- Clean up BuildFile API
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants