带有 Quarkus 和非 Quarkus 模块的混合多模块 Maven 项目 - 有没有办法在开发模式下顺利运行?

问题描述 投票:0回答:1

所以我有一个 Quarkus 项目,我想在开发模式下运行

mvn quarkus:dev

我有一个混合项目,其中包含一个 Quarkus 模块和一个纯 Java 的非 Quarkus 项目。

我们称它们为 module1(非 quarkus)和 module2(quarkus)。 模块2依赖于模块1。

当我执行时

$ cd module2
$ mvn quarkus:dev

出现以下错误:

[错误]无法在项目模块2上执行目标:无法解析 项目 xxx:module2:jar:1.0 的依赖项:以下工件 无法解析:xxx.root:module1:jar:1.0(不存在): xxx.root:module1:jar:1.0 未找到 https://repo.maven.apache.org/maven2 在之前的尝试中。这 失败已缓存在本地存储库中,并且解决方案未缓存 重新尝试,直到中央更新间隔已过或 强制更新

好的,依赖没有设置,因为 module1 没有本地安装,无法远程解析。当我在 module1 和根目录上执行

mvn clean install
时,我终于可以在 module2 的文件夹中执行
mvn quarkus:dev
了。

有什么办法可以让体验更流畅吗?我的意思是,如果我不断更改 module1,我是否必须始终这样做

mvn clean install

我的项目结构如下所示:

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

root 的 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的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的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 ...
java maven quarkus
1个回答
0
投票

在所描述的示例中,您应该能够在根项目 POM 的

quarkus-maven-plugin
部分中添加
pluginManagement
(没有目标)(保持应用程序模块中配置的
quarkus:*
目标),然后执行从根源上
mvn compile quarkus:dev
。 在这种情况下,Maven 将了解工作区中的所有模块,并且
quarkus:dev
将启动应用程序模块。

请注意,实际上,一旦您对其源应用了更改,您并不需要总是重新安装

module1
。如果您的本地存储库包含过时版本的
module1
,开发模式仍将从工作区而不是本地存储库中选取源和类。本地存储库中存在
module1
工件只是为了让 Maven 解决依赖关系时不会失败。 您看到的错误是 Maven 在到达 Quarkus 插件之前抛出的。然后 Quarkus 插件将正确找到该模块、其源代码和类。

如果工作区仅包含一个 Quarkus 应用程序,则上述建议将起作用。如果包含多个,则模块列表中的第一个 Quarkus 应用程序将首先启动。一旦该应用程序的开发模式终止,下一个应用程序将启动。

对于包含多个应用程序的工作区,您可以在根 POM 中使用 Maven 配置文件。例如,您可以从默认的

modules
列表中删除 Quarkus 应用程序模块,并将它们添加到具有
<activeByDefault>true</activeByDefault>
的配置文件中,这样当您在命令行上构建项目时,所有模块都会被构建。 然后,您可以为每个应用程序模块创建一个配置文件,例如
app1Dev
只会添加
app1
模块,而不添加其他应用程序。这样,当您从根目录启动
mvn -Papp1Dev
时,Maven 将在您的工作区中仅看到一个 Quarkus 应用程序。您还可以添加值
profile/build/defaultGoal
compile quarkus:dev
,并且
mvn -Papp1Dev
应该足以在开发模式下启动
app1

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.