Multiple quarkus applications in multi-module maven build with quarkus:dev

Viewed 839

I have a solution with multiple applications (different but closely related micro-services) that share common and fairly complex code. The project uses Maven and is currently setup as:

- Root pom
  - Quarkus application 1
  - Quarkus application 2
  - Shared library

My problem is that I would like to use development mode to pick up changes, and I can't get that to work. With a single Quarkus application it is supported and it is possible to build with quarkus:dev from the root folder. With two Quarkus applications it is not clear which one that is started.

I can use the -pl option for Maven to select the one I want to start, but then it doesn't find the shared library (as the build is done from the selected project rather than the root). To fix that I can install the shared library first (mvn install), but then Quarkus will naturally use the installed version and I want to use the live code so that changes in the shared library are picked up.

If this is not possible I will keep the model in one application and use it "installed" from the other; that way live-coding should at least work in one of the applications. Before I do that I wonder if there is a way to accomplish what I want with multiple Quarkus applications where a specific application is started in development mode from a top-level Maven build?

2 Answers

This limitation comes mostly from Maven. If you launch the app with -pl or -f, it’s Maven that fails to find the dependency, not Quarkus, right? Quarkus will discover the complete workspace but Maven fails before that.

What you could try is using maven profiles. I.e. one profile would enable the module containing one app and the other profile - the app. The when you launch from the root, you would enable the profile you need.

Having something like this:

  <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>
      <dependency>
        <groupId>org.acme</groupId>
        <artifactId>acme-common</artifactId>
        <version>${project.version}</version>
      </dependency>
    </dependencies>
  </dependencyManagement>
  <modules>
    <module>common</module>
  </modules>
  <build>
    <plugins>
      <plugin>
        <groupId>${quarkus.platform.group-id}</groupId>
        <artifactId>quarkus-maven-plugin</artifactId>
        <version>${quarkus.platform.version}</version>
        <extensions>true</extensions>
      </plugin>
    </plugins>
  </build>
  <profiles>
    <profile>
      <id>app1Dev</id>
      <modules>
        <module>app1</module>
      </modules>
      <build>
        <defaultGoal>clean compile quarkus:dev</defaultGoal>
      </build>
    </profile>
    <profile>
      <id>app2Dev</id>
      <modules>
        <module>app2</module>
      </modules>
      <build>
        <defaultGoal>clean compile quarkus:dev</defaultGoal>
      </build>
    </profile>
  </profiles>

You can launch the app1 from the root dir of the project with mvn -Papp1Dev and the app2 with mvn -Papp2Dev.

Or you can remove the defaultGoal and rename the profiles to app1 and app2, you can use commands like mvn -Papp1 compile quarkus:dev.

Related