简体   繁体   中英

Maven multi module project with Quarkus in dev mode

I am new to Quarkus and try to use it in a Maven multi module project. My project is structured as followed:

- quarkustest (pom)
  - quarkustest-application (jar)
  - quarkustest-backend (pom)
    - quarkustest-backend-rest-api (jar)
  - quarkustest-dependencies (pom)
  - quarkustest-parent (pom)

The application module executes the quarkus-maven-plugin with build-goal. The quarkustest-backend-rest-api contains a simple REST controller and thus also a beans.xml in /src/main/resources/META-INF . The rest-api-module is references by the application module.

If I package the whole project with mvn package , the resulting runner-jar works as expected. However, if I try to start the project in dev mode with mvn compile quarkus:dev , I get following exception:

ERROR] Failed to execute goal io.quarkus:quarkus-maven-plugin:1.0.0.CR2:dev (default-cli) on project quarkustest-application: Failed to run: Failed to resolve Quarkus application model: Failed to resolve dependencies for test.quarkustest:quarkustest-application:jar:1.0.0-SNAPSHOT: Could not find artifact test.quarkustest:quarkustest-backend-rest-api:jar:1.0.0-SNAPSHOT -> [Help 1]

I am not quite sure how to solve this. Is there any kind of best practice on multi module projects for Quarkus? Any obvious mistake I am doing here?

Edit 1 (relevant pom files)

quarkustest-application

<parent>
    <groupId>test.quarkustest</groupId>
    <artifactId>quarkustest-parent</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <relativePath>../quarkustest-parent</relativePath>
</parent>

<artifactId>quarkustest-application</artifactId>

<dependencies>
    <dependency>
        <groupId>test.quarkustest</groupId>
        <artifactId>quarkustest-backend-rest-api</artifactId>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>io.quarkus</groupId>
            <artifactId>quarkus-maven-plugin</artifactId>
            <version>${quarkus-plugin.version}</version>
            <executions>
                <execution>
                    <goals>
                        <goal>build</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

quarkustest-parent

<parent>
    <groupId>test.quarkustest</groupId>
    <artifactId>quarkustest-dependencies</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <relativePath>../quarkustest-dependencies</relativePath>
</parent>

<artifactId>quarkustest-parent</artifactId>
<packaging>pom</packaging>

quarkustest-dependencies

<groupId>test.quarkustest</groupId>
<artifactId>quarkustest-dependencies</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>pom</packaging>

<properties>
    ...
</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>
        <dependency>
            <groupId>test.quarkustest</groupId>
            <artifactId>quarkustest-backend-rest-api</artifactId>
            <version>1.0.0-SNAPSHOT</version>
        </dependency>
    </dependencies>
</dependencyManagement>

<build>
    <plugins>
        <plugin>
            <groupId>io.quarkus</groupId>
            <artifactId>quarkus-maven-plugin</artifactId>
            <version>${quarkus-plugin.version}</version>
        </plugin>
    </plugins>
</build>

quarkustest (aggregator)

<parent>
    <groupId>test.quarkustest</groupId>
    <artifactId>quarkustest-parent</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <relativePath>quarkustest-parent</relativePath>
</parent>

<artifactId>quarkustest</artifactId>
<packaging>pom</packaging>

<modules>
    <module>quarkustest-dependencies</module>
    <module>quarkustest-parent</module>
    <module>quarkustest-backend</module>
    <module>quarkustest-application</module>
</modules>

If you've never ran mvn install it might be because when you're in a subproject maven does not look in its sibling projects to resolve the dependencies, it only looks in the local maven repository which does not contain the dependency. If you have ran mvn install it might be something else at play.

Keep the quarkus-maven-plugin in the quarkustest-application and run

  1. mvn clean install
  2. mvn quarkus:dev -pl quarkustest-application

Now it will pick up changes in all submodules.

I was able to successfully run quarkus submodule in dev (with dependency to other module) in the following way:

  1. Install "Quarkus Run Configs" plugin
  2. Define new Run configuration for Quarkus -> in VM options provide additional maven parameters in:

-Dmaven.am -Dmaven.pl=<name-of-you-quarkus-module>

  1. In parent pom define quarkus plugin:

     <plugin> <groupId>io.quarkus</groupId> <artifactId>quarkus-maven-plugin</artifactId> <version>${quarkus-plugin.version}</version> </plugin>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM