javamavenquarkus

Mixed Multi-module maven project with Quarkus and non-Quarkus modules - is there a way to run smoothly on dev mode?


The applied solution is at the bottom of the question


So I have a Quarkus project that I want to run in dev mode with mvn quarkus:dev.

I have a mixed project that contains one Quarkus module and a non-Quarkus project that is pure Java.

Let us call them module1 (non-quarkus) and module2 (quarkus). The module2 have a dependency on module1.

When I execute

$ cd module2
$ mvn quarkus:dev

The following error occurs:

[ERROR] Failed to execute goal on project module2: Could not resolve dependencies for project xxx:module2:jar:1.0: The following artifacts could not be resolved: xxx.root:module1:jar:1.0 (absent): xxx.root:module1:jar:1.0 was not found in https://repo.maven.apache.org/maven2 during a previous attempt. This failure was cached in the local repository and resolution is not reattempted until the update interval of central has elapsed or updates are forced

Okay, the dependencies are not set because module1 is not locally installed and could not be resolved remotely. When I do mvn clean install on module1 and on the root, I can finally do mvn quarkus:dev inside module2's folder.

Is there anyway to have a smoother experience? I mean, if I'm constantly changing module1, will I have to always do mvn clean install?

My project structure looks like this:

root
├── module1 (non quarkus project)
└── module2 (quarkus project)

root's pom.xml

<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>xxx</groupId>
    <artifactId>root</artifactId>
    <version>1.0</version>
    <packaging>pom</packaging>
    <modules>
        <module>module1</module>
        <module>module2</module>
    </modules>
</project>

module1's pom.xml

<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>xxx</groupId>
        <artifactId>root</artifactId>
        <version>1.0</version>
    </parent>

    <artifactId>module1</artifactId>

    <properties>
        <maven.compiler.source>21</maven.compiler.source>
        <maven.compiler.target>21</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

</project>

module2's pom.xml

<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>xxx</groupId>
        <artifactId>root</artifactId>
        <version>1.0</version>
    </parent>

    <artifactId>module2</artifactId>

    <properties>
        <compiler-plugin.version>3.13.0</compiler-plugin.version>
        <maven.compiler.release>21</maven.compiler.release>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <quarkus.platform.artifact-id>quarkus-bom</quarkus.platform.artifact-id>
        <quarkus.platform.group-id>io.quarkus.platform</quarkus.platform.group-id>
        <quarkus.platform.version>3.17.7</quarkus.platform.version>
        <skipITs>true</skipITs>
        <surefire-plugin.version>3.5.0</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.synkronize</groupId>
            <artifactId>commons</artifactId>
            <version>1.0</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>io.quarkus</groupId>
            <artifactId>quarkus-rest</artifactId>
        </dependency>
    </dependencies>

.... and the quarkus maven plugins ...

Applied Solution

I did what Alexey said at his answer and I followed this tutorial.

To run N modules in parallel without having to open N separate terminals to run mvn quarkus dev -Pmodule1 and mvn quarkus:dev -Pmodule2 I've made use of Run Configurations of IntelliJ by creating 2 Maven run configurations and configuring both of them to point to the correct profile as per the following images

Maven Run Configurations Maven Run Configurations

Module 1 Configuration Module 1 Configuration

Module 2 Configuration Module 2 Configuration


Solution

  • In an example described, you should be able to add the quarkus-maven-plugin (w/o the goals) in the build/plugins section of the root project POM (keeping the quarkus:* goals configured in the app module) and then execute mvn compile quarkus:dev from the root. In this case Maven will be aware of all the modules in the workspace and quarkus:dev will work launch the app module.

    Note that actually, you don't need to always re-install module1 once you applied changes to its sources. If your local repository contains an outdated version of module1, dev mode will still be picking sources and classes from the workspace instead of from the local repo. The presence of module1 artifacts in the local repo would be necessary only to let Maven not fail resolving dependencies. The error that you see is thrown by Maven before it gets to the Quarkus plugin. The Quarkus plugin then will correctly find the module, its sources and classes.

    The suggestion above will work though if the workspace contains only one Quarkus application. If it contains more than one the the first Quarkus application in the module list will be launched first. Once dev mode is terminated for that app, the next one will be launched.

    For workspaces that include more than one application, you use Maven profiles in the root POM. For example, you could remove Quarkus application modules from the default modules list and add them in a profile that has <activeByDefault>true</activeByDefault>, so that when you build your project on the command line, all the modules will be built. Then for each application module you could create a profile, e.g. app1Dev that would add only app1 module but not other applications. So that when you launch mvn -Papp1Dev from the root directory, Maven will see only one Quarkus application in your workspace. You can also add profile/build/defaultGoal with value compile quarkus:dev and mvn -Papp1Dev should be enough to launch app1 in dev mode.