在开发模式下使用 Quarkus 的 Maven 多模块项目

nil*_*ils 13 java maven quarkus

我是 Quarkus 的新手,并尝试在 Maven 多模块项目中使用它。我的项目结构如下:

- quarkustest (pom)
  - quarkustest-application (jar)
  - quarkustest-backend (pom)
    - quarkustest-backend-rest-api (jar)
  - quarkustest-dependencies (pom)
  - quarkustest-parent (pom)
Run Code Online (Sandbox Code Playgroud)

应用程序模块使用 build-goal 执行 quarkus-maven-plugin。的quarkustest-backend-rest-api包含一个简单的REST控制器并因此也是一个beans.xml/src/main/resources/META-INF。rest-api-module 是应用程序模块的引用。

如果我使用 打包整个项目mvn package,则生成的 runner-jar 将按预期工作。但是,如果我尝试使用 以开发模式启动项目,则会出现mvn compile quarkus:dev以下异常:

错误] 无法在项目 quarkustest-application 上执行目标 io.quarkus:quarkus-maven-plugin:1.0.0.CR2:dev (default-cli):无法运行:无法解析 Quarkus 应用程序模型:无法解析依赖关系test.quarkustest:quarkustest-application:jar:1.0.0-SNAPSHOT: 找不到工件 test.quarkustest:quarkustest-backend-rest-api:jar:1.0.0-SNAPSHOT -> [帮助 1]

我不太确定如何解决这个问题。Quarkus 的多模块项目是否有任何最佳实践?我在这里做的任何明显错误?

编辑1(相关pom文件)

quarkustest-应用程序

<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>
Run Code Online (Sandbox Code Playgroud)

夸克测试父

<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>
Run Code Online (Sandbox Code Playgroud)

夸克测试依赖

<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>
Run Code Online (Sandbox Code Playgroud)

quarkustest(聚合器)

<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>
Run Code Online (Sandbox Code Playgroud)

小智 2

如果您从未运行过mvn install,可能是因为当您在子项目中时,maven 不会在其同级项目中查找来解决依赖项,它只在不包含依赖项的本地 maven 存储库中查找。如果您已经跑步,mvn install则可能是其他原因在起作用。