0

我坚持基于 Hexagonal 架构构建复杂的 Maven 多模块项目。

我的 Maven 模块结构看起来像这样

|   graphql-intro (root module)
|   graphql-intro.xml
+-- bootloader (module)
|    +--- src/main/java/com/intro/graphql/ApplicationInitializer
|    +--- bootloader.xml
|
+-- domain (module)
|     +--- domain.xml
|
+-- infrastructure-adapters (module, root module for adapters)
|     +--- infrastructure-adapters.xml
|
|     +--- adapter-api-graphql (module)
|     |   +--- adapter-api-graphql.xml
|
|     +--- adapter-persistence-in-memory (module)
|     |   +--- adapter-persistence-in-memory.xml
|
|     +--- adapter-persistence-spring-data-jpa (module)
|     |   +--- adapter-persistence-spring-data-jpa.xml

root.xml 看起来像这样

    ...
    <packaging>pom</packaging>
    <modules>
        <module>domain</module>
        <module>infrastructure-adapters</module>
        <module>bootloader</module>
    </modules>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.2.4.RELEASE</version>
    </parent>
    <groupId>com.into.graphql</groupId>
    <artifactId>graphql-into</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    ...
    <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
        <version>${spring-boot.version}</version>
        <executions>
            <execution>
                <goals>
                    <goal>repackage</goal>
                </goals>
            </execution>
        </executions>
        <configuration>
            <mainClass>com.intro.graphql.ApplicationInitializer</mainClass>
        </configuration>
    </plugin>
    ...

这是基础设施适配器.xml

    <parent>
        <artifactId>graphql-into</artifactId>
        <groupId>com.into.graphql</groupId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>

    <packaging>pom</packaging>

    <artifactId>infrastructure-adapters</artifactId>
    <name>infrastructure-adapters</name>
    <description>infrastructure-adapters</description>

    <modules>
        <module>adapter-persistence-spring-data-jpa</module>
        <module>adapter-persistence-in-memory</module>
        <module>adapter-api-graphql-kickstarter</module>
    </modules>

问题是在构建持久性适配器期间看不到域模块中的类,这是spring data jpa持久性适配器中的pom

<parent>
        <groupId>com.into.graphql</groupId>
        <artifactId>infrastructure-adapters</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>adapter-persistence-spring-data-jpa</artifactId>
    <name>adapter-persistence-spring-data-jpa</name>
    <description>adapter-persistence-spring-data-jpa</description>

    <dependencies>
        ...
        <dependency>
            <groupId>com.into.graphql</groupId>
            <artifactId>domain</artifactId>
        </dependency>
        ...
    </dependencies>

错误是

[INFO] graphql-into ....................................... SUCCESS [  1.875 s]
[INFO] domain ............................................. SUCCESS [  2.582 s]
[INFO] infrastructure-adapters ............................ SUCCESS [  0.092 s]
[INFO] adapter-persistence-spring-data-jpa ................ FAILURE [  2.118 s]
[INFO] adapter-persistence-in-memory ...................... SKIPPED
[INFO] adapter-api-graphql-kickstarter .................... SKIPPED
[INFO] bootloader ......................................... SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  7.152 s
[INFO] Finished at: 2020-04-30T11:17:26+02:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project adapter-persistence-spring-data-jpa: Compilation failure: Compilation failure:
[ERROR] path/graphql-into/infrastructure-adapters/adapter-persistence-spring-data-jpa/src/main/java/com/intro/graphql/persistance/jpa/products/ProductDaoAdapter.java:[3,33] package com.intro.grap
hql.dealers does not exist (it is package from domain module)

有谁知道可能是什么问题,内部模块可以依赖于外部模块,或者构建顺序可能不好?

4

1 回答 1

0

问题解决了,我将构建配置移至spring-boot-maven-plugin引导加载程序 pom,现在构建工作。不幸的是,我不知道它解决问题的原因。

于 2020-04-30T15:37:41.507 回答