Maven多模块依赖编译问题

时间:2020-12-29 20:22:13

标签: java spring spring-boot hibernate maven

在使用 IntelliJ 的多模块项目中,我的 Maven 依赖项有问题。

以下是我的maven模块的结构: (1) venus 是根模块。 (2) architectarchitect-com 模块的父模块。 (3) actions-comactions模块的子模块,servicesactions模块的父模块。 (4) architectservices 是根模块的直接子模块

- venus
  - architect
    - architect-com
      - src [java classes here]
  - services
    - actions
      - actions-com
         - src [java classes here]
        

架构师、服务和操作模块没有 src 文件夹(我删除了它们,因为我认为父模块不需要 src 文件夹。)

这里是模块的 POM。

// Venus - 根模块

<?xml version="1.0" encoding="UTF-8"?>
<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>

    <groupId>co.shock</groupId>
    <artifactId>venus</artifactId>
    <version>1.0-SNAPSHOT</version>
    <modules>
        <module>services</module>
        <module>services/actions</module>
        <module>services/actions/actions-com</module>
        <module>architect</module>
        <module>architect/architect-com</module>
    </modules>
    <packaging>pom</packaging>
</project>

// 架构师

<?xml version="1.0" encoding="UTF-8"?>
<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>
        <artifactId>venus</artifactId>
        <groupId>co.shock</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>


    <name>architect</name>
    <groupId>co.shock.jupiter</groupId>
    <artifactId>architect</artifactId>
    <packaging>pom</packaging>

    <modules>
        <module>architect-com</module>
    </modules>

</project>

// Architect-com

<?xml version="1.0" encoding="UTF-8"?>
<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>
        <artifactId>architect</artifactId>
        <groupId>co.shock.venus</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>


    <name>Architect - Com</name>
    <groupId>co.shock.venus.architect</groupId>
    <artifactId>architect-com</artifactId>

    <dependencies>
      // SPRING AND HIBERNATE DEPENDENCIES HERE
    </dependencies>
</project>

// 服务

<?xml version="1.0" encoding="UTF-8"?>
<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>
        <artifactId>venus</artifactId>
        <groupId>co.shock</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>


    <name>Services</name>
    <groupId>co.shock.venus</groupId>
    <artifactId>services</artifactId>
    <packaging>pom</packaging>
    <version>1.0-SNAPSHOT</version>

    <modules>
        <module>actions</module>
    </modules>

</project>

// 动作

<?xml version="1.0" encoding="UTF-8"?>
<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>
    <version>1.0-SNAPSHOT</version>

    <parent>
        <artifactId>services</artifactId>
        <groupId>co.shock.venus</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>


    <name>Services - Actions</name>
    <groupId>co.shock.venus.services</groupId>
    <artifactId>actions</artifactId>
    <packaging>pom</packaging>

    <modules>
        <module>actions-com</module>
    </modules>

</project>

// actions-com

<?xml version="1.0" encoding="UTF-8"?>
<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>
        <artifactId>actions</artifactId>
        <groupId>co.shock.venus.services</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>

    <name>Services - Actions - Com</name>
    <groupId>co.shock.venus.services.actions</groupId>
    <artifactId>actions-com</artifactId>

    <dependencies>
        <dependency>
            <groupId>co.shock.venus.architect</groupId>
            <artifactId>architect-com</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
    </dependencies>


    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <configuration>
                    <source>8</source>
                    <target>8</target>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

actions-com 模块导入 architect-com,如上面的 pom 所示。当我编译 actions-com 模块时,出现以下错误:

C:\3_projects\venus\services\actions\actions-com>mvn clean compile
[INFO] Scanning for projects...
[INFO]
[INFO] ---------< co.shock.venus.services.actions:actions-com >---------
[INFO] Building Services - Actions - Com 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.256 s
[INFO] Finished at: 2020-12-29T21:02:12+01:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project actions-com: Could not resolve dependencies for project co.shock
.venus.services.actions:actions-com:jar:1.0-SNAPSHOT: Failed to collect dependencies at co.shock.venus
.architect:architect-com:jar:1.0-SNAPSHOT: Failed to read artifact descriptor for co.shock.venus
.architect:architect-com:jar:1.0-SNAPSHOT: Could not find artifact co.shock:venus:pom:1.0-S
NAPSHOT -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException

以下是我的 .m2 存储库的路径,其中构建了 Architect-com。这是快照文件夹的内容

C:\Users\user\.m2\repository\co\shock\venus\architect\architect-com\1.0-SNAPSHOT
   - _remote.repositories
   - architect-com-1.0-SNAPSHOT.jar
   - architect-com-1.0-SNAPSHOT.pom
   - maven-metadata-local.xml

我用谷歌搜索了一整天,但找不到任何解决方案。我希望有人指出正确的方向。

我做错了什么?

1 个答案:

答案 0 :(得分:0)

看错误msg的最后一句:Could not find artifact co.shock:venus:pom:1.0-SNAPSHOT

services 包含:

    <parent>
        <artifactId>venus</artifactId>
        <groupId>co.shock</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>

金星包含:

    <groupId>co.shock</groupId>
    <artifactId>jupiter</artifactId> <!-- should be 'venus' -->
    <version>1.0-SNAPSHOT</version>

你只是把行星搞混了。 :)