jiayaoO3O
jiayaoO3O

Reputation: 63

What are the best practices for creating a quarkus multi-module project?

I want to create a multi-module quarkus project, here's what I did :

  1. Create a normal qurakus project by IDEA
  2. Right click on the project folder and select "Add Module", Added 3 sub-modules : "controller","res","package".

I want the "package" module to be an uber-jar, as a runnable jar that contains all the other modules, so I modified the pom.xml file of each module :

this is the root module pom.xml :

<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"
         xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <modelVersion>4.0.0</modelVersion>
    <groupId>io.github.jiayaoO3O</groupId>
    <artifactId>yirgacheffe</artifactId>
    <packaging>pom</packaging>
    <version>1.0.0-SNAPSHOT</version>
    <modules>
        <module>controller</module>
        <module>res</module>
        <module>package</module>
    </modules>
    <properties>
        <compiler-plugin.version>3.8.1</compiler-plugin.version>
        <maven.compiler.parameters>true</maven.compiler.parameters>
        <maven.compiler.source>16</maven.compiler.source>
        <maven.compiler.target>16</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <quarkus-plugin.version>1.13.0.Final</quarkus-plugin.version>
        <quarkus.platform.artifact-id>quarkus-universe-bom</quarkus.platform.artifact-id>
        <quarkus.platform.group-id>io.quarkus</quarkus.platform.group-id>
        <quarkus.platform.version>1.13.0.Final</quarkus.platform.version>
        <surefire-plugin.version>3.0.0-M5</surefire-plugin.version>
    </properties>
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>${quarkus.platform.group-id}</groupId>
                <artifactId>${quarkus.platform.artifact-id}</artifactId>
                <version>${quarkus.platform.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>io.quarkus</groupId>
            <artifactId>quarkus-resteasy-reactive</artifactId>
        </dependency>
        <dependency>
            <groupId>io.quarkus</groupId>
            <artifactId>quarkus-arc</artifactId>
        </dependency>
        <dependency>
            <groupId>io.quarkus</groupId>
            <artifactId>quarkus-junit5</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.rest-assured</groupId>
            <artifactId>rest-assured</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.jboss.jandex</groupId>
                <artifactId>jandex-maven-plugin</artifactId>
                <version>1.0.8</version>
                <executions>
                    <execution>
                        <id>make-index</id>
                        <goals>
                            <goal>jandex</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>io.quarkus</groupId>
                <artifactId>quarkus-maven-plugin</artifactId>
                <version>${quarkus-plugin.version}</version>
                <extensions>true</extensions>
                <executions>
                    <execution>
                        <goals>
                            <goal>build</goal>
                            <goal>generate-code</goal>
                            <goal>generate-code-tests</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>${compiler-plugin.version}</version>
            </plugin>
            <plugin>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>${surefire-plugin.version}</version>
                <configuration>
                    <systemPropertyVariables>
                        <java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
                        <maven.home>${maven.home}</maven.home>
                    </systemPropertyVariables>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <profiles>
        <profile>
            <id>native</id>
            <activation>
                <property>
                    <name>native</name>
                </property>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <artifactId>maven-failsafe-plugin</artifactId>
                        <version>${surefire-plugin.version}</version>
                        <executions>
                            <execution>
                                <goals>
                                    <goal>integration-test</goal>
                                    <goal>verify</goal>
                                </goals>
                                <configuration>
                                    <systemPropertyVariables>
                                        <native.image.path>
                                            ${project.build.directory}/${project.build.finalName}-runner
                                        </native.image.path>
                                        <java.util.logging.manager>org.jboss.logmanager.LogManager
                                        </java.util.logging.manager>
                                        <maven.home>${maven.home}</maven.home>
                                    </systemPropertyVariables>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
            <properties>
                <quarkus.package.type>native</quarkus.package.type>
            </properties>
        </profile>
    </profiles>
</project>

this is the controller module pom.xml :

<?xml version="1.0" encoding="UTF-8"?>
<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">
    <parent>
        <artifactId>yirgacheffe</artifactId>
        <groupId>io.github.jiayaoO3O</groupId>
        <version>1.0.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>controller</artifactId>

    <properties>
        <maven.compiler.source>16</maven.compiler.source>
        <maven.compiler.target>16</maven.compiler.target>
    </properties>

</project>

this is the res module pom.xml :

<?xml version="1.0" encoding="UTF-8"?>
<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">
    <parent>
        <artifactId>yirgacheffe</artifactId>
        <groupId>io.github.jiayaoO3O</groupId>
        <version>1.0.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>res</artifactId>

    <properties>
        <maven.compiler.source>16</maven.compiler.source>
        <maven.compiler.target>16</maven.compiler.target>
    </properties>

</project>

this is the package module pom.xml :

<?xml version="1.0" encoding="UTF-8"?>
<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">
    <parent>
        <artifactId>yirgacheffe</artifactId>
        <groupId>io.github.jiayaoO3O</groupId>
        <version>1.0.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>package</artifactId>

    <properties>
        <maven.compiler.source>16</maven.compiler.source>
        <maven.compiler.target>16</maven.compiler.target>
    </properties>

    <dependencies>
        <dependency>
            <groupId>io.github.jiayaoO3O</groupId>
            <artifactId>controller</artifactId>
            <version>${project.parent.version}</version>

        </dependency>
        <dependency>
            <groupId>io.github.jiayaoO3O</groupId>
            <artifactId>res</artifactId>
            <version>${project.parent.version}</version>
        </dependency>
    </dependencies>
</project>
  1. At the end, I added the application.properties file to the resources folder of the "package" module, adding the required configuration.

Finally, I ran mvn clean package in the root module, and got the package-1.0.0-SNAPSHOT-runner.jar file, which worked perfectly.

So the question I want to ask is, are my steps above, the best practice for building multi-module quarkus projects? Are there any issues that I am not aware of?

Upvotes: 4

Views: 14543

Answers (3)

Borislav Gizdov
Borislav Gizdov

Reputation: 1960

I have found this sample multi module Quarkus project for Quarkus 1:

https://github.com/Rashmini/Quarkus-multimodule-project

enter image description here

Edit:

The above project is a bit old, I created a new sample multi-module project with Quarkus 2.4.2 Final, which contains two modules quickstart-core and quickstart-rest, with jandex-maven-plugin for CDI bean discovery.

https://github.com/bgizdov/quarkus-multi-module-project-quickstart

Edit: Updated to latest Quarkus LTS version 3.15

Upvotes: 7

stwissel
stwissel

Reputation: 20394

You want to improve your setup and simplify it:

  • separate Maven reactor (the pom containing <modules> from the parent project (the pop you keep <properties> and <dependencyManagement>
  • remove duplicate properties, one in the parent project suffices
  • have one <dependencyManagement> and one <pluingManagement> in parent and none in any other module
  • have the quarkus-maven-plugin only in modules that listen to a port, for the others use the Yandex plugin
  • separate ports for the modules

I have a sample project and more details here

Upvotes: 1

Illya Kysil
Illya Kysil

Reputation: 1756

The structure described in the question looks reasonable. I would suggest the following improvements though:

  • there is no need to repeat maven.compiler.source and maven.compiler.target properties in the child modules, they are inherited from the <parent>;
  • there is no need to run quarkus-maven-plugin in all modules, move it to the package module;
  • same applies to the profile native.

Keep the jandex-maven-plugin configured for all modules, as described in the Quarkus - Working with multi-module projects.

Upvotes: 7

Related Questions