Skip to content

Make initialize-spring-boot-migration work with simple multi Maven module project #270

Closed
@fabapp2

Description

@fabapp2

Currently, the recipe initialize-spring-boot-migration only works for single module projects.
As a first step to support multi maven module projects this recipe should work with a simple multi module project.

What needs to be done

Setup project

Parent/root module

<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>org.example</groupId>
    <artifactId>parent</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>pom</packaging>
    <properties>
        <maven.compiler.source>17</maven.compiler.source>
        <maven.compiler.target>17</maven.compiler.target>
    </properties>
    <modules>
        <module>module1</module>
        <module>module2</module>
    </modules>
</project>

Application module

<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.example</groupId>
        <artifactId>parent</artifactId>
        <version>1.0-SNAPSHOT</version>
        <relativePath>../pom.xml</relativePath>
    </parent>
    <artifactId>module1</artifactId>
    <properties>
        <maven.compiler.source>17</maven.compiler.source>
        <maven.compiler.target>17</maven.compiler.target>
        <spring-boot.version>2.7.2</spring-boot.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.example</groupId>
            <artifactId>module2</artifactId>
            <version>${project.version}</version>
        </dependency>
    </dependencies>
</project>

Component module

<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.example</groupId>
        <artifactId>parent</artifactId>
        <version>1.0-SNAPSHOT</version>
        <relativePath>../pom.xml</relativePath>
    </parent>
    <artifactId>module2</artifactId>
    <properties>
        <maven.compiler.source>17</maven.compiler.source>
        <maven.compiler.target>17</maven.compiler.target>
    </properties>
</project>

Expected result:

  • dependencyManagement section with Spring dependencies should be added to parent pom
  • Spring Boot Application class and test should be added to application module
  • application.properties should be added to application module
  • dependencies should be added to application module

TODOs

  • AddDependencies: adds dependencies to topmost application modules. This is oversimplified. The correct module has to be calculated depending on the usage.
  • RemoveDependenciesMatchingRegex: Removes dependencies from the modules where AddDependency was applied.
  • AddMavenPlugin: Adds the spring-boot-maven-plugin to all application modules
  • AddSpringBootApplicationPropertiesAction: Adds application.properties to all application modules
  • AddSpringBootMainClassAction: Adds main class to all application modules
  • AddSpringBootContextTestClassAction: Adds main class to all application modules
  • BuildPackaging: Changes type to jar for application modules
  • Make MultiModuleHandler and abstract class providing the setter for Action

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions