MavenError:未能执行project:无法解决Maven Multimodule项目中的依赖关系

时间:2023-01-26 21:05:43

I am trying to create a maven multi-module project. the project create successfully, but when i trying to use one module as a dependency of another module it generate an exception. When i create a module, using eclipse, i was select packaging as a jar, but when the module is create, the packaging tag was not mention in child pom.xml, and i manually insert the packaging tag as a jar. following is my parent pom.xml:

我正在尝试创建一个maven多模块项目。项目创建成功,但是当我尝试使用一个模块作为另一个模块的依赖时,它会产生一个异常。当我使用eclipse创建一个模块时,我选择将打包作为jar,但是在创建模块时,在子pom中没有提到打包标记。xml,我手工将打包标记插入到jar中。下面是我的父母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>
<groupId>com.netsol</groupId>
<artifactId>empirecl</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
-------------------------
<modules>
    <module>empirecl-web</module>
    <module>empirecl-dao</module>
    <module>empirecl-service</module>
    <module>empirecl-api</module>
</modules>

Dao Child Module:

刀子模块:

<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>com.netsol</groupId>
    <artifactId>empirecl</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <relativePath>../pom.xml</relativePath>
</parent>
<artifactId>empirecl-dao</artifactId>
<packaging>jar</packaging>
<name>empirecl-dao</name>
------------------------

Service Child Module:

服务子模块:

<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>com.netsol</groupId>
    <artifactId>empirecl</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <relativePath>../pom.xml</relativePath>
</parent>
<artifactId>empirecl-service</artifactId>
<packaging>jar</packaging>
<name>empirecl-service</name>

<dependencies>
    <dependency>
        <groupId>com.netsol</groupId>
        <artifactId>empirecl-dao</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <type>jar</type>
    </dependency>
------------------------------------------

The Dao module maven clean and install successfully, but when i trying to use service module, it will generate an following exception:

Dao模块maven清理安装成功,但是当我尝试使用服务模块时,会产生以下异常:

[ERROR] Failed to execute goal on project empirecl-service: Could not resolve dependencies for project com.netsol:empirecl-service:jar:0.0.1-SNAPSHOT: Failed to collect dependencies at com.netsol:empirecl-dao:jar:0.0.1-SNAPSHOT: Failed to read artifact descriptor for com.netsol:empirecl-dao:jar:0.0.1-SNAPSHOT: Could not find artifact com.netsol:empirecl:pom:0.0.1-SNAPSHOT -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal on project empirecl-service: Could not resolve dependencies for project com.netsol:empirecl-service:jar:0.0.1-SNAPSHOT: Failed to collect dependencies at com.netsol:empirecl-dao:jar:0.0.1-SNAPSHOT

I am trying the find to solution from web, but still the solution is not found. In eclipse when i open the Dependency Hierarchy of service module, it shown the DAO module as a folder not jar. below is the screen shot of Dependency Hierarchy of service module.

我正在尝试从web上找到解决方案,但是仍然没有找到解决方案。在eclipse中,当我打开服务模块的依赖层次结构时,它将DAO模块显示为一个文件夹而不是jar。下面是服务模块的依赖层次结构的屏幕截图。

MavenError:未能执行project:无法解决Maven Multimodule项目中的依赖关系

1 个解决方案

#1


14  

In case anybody comes back to this, I think the problem here was failing to install the parent pom first, which all these submodules depend on, so the Maven Reactor can't collect the necessary dependencies to build the submodule.

如果有人回到这个问题,我认为这里的问题是没有首先安装父pom,这是所有这些子模块所依赖的,因此Maven反应器无法收集必要的依赖项来构建子模块。

So from the root directory (here D:\luna_workspace\empire_club\empirecl) it probably just needs a:

因此,从根目录(这里D:\luna_workspace\帝国-俱乐部\帝国-俱乐部)它可能只需要一个:

mvn clean install

(Aside: <relativePath>../pom.xml</relativePath> is not really necessary as it's the default value).

(旁白:< relativePath > . . / pom。xml实际上并不是必需的,因为它是默认值)。

#1


14  

In case anybody comes back to this, I think the problem here was failing to install the parent pom first, which all these submodules depend on, so the Maven Reactor can't collect the necessary dependencies to build the submodule.

如果有人回到这个问题,我认为这里的问题是没有首先安装父pom,这是所有这些子模块所依赖的,因此Maven反应器无法收集必要的依赖项来构建子模块。

So from the root directory (here D:\luna_workspace\empire_club\empirecl) it probably just needs a:

因此,从根目录(这里D:\luna_workspace\帝国-俱乐部\帝国-俱乐部)它可能只需要一个:

mvn clean install

(Aside: <relativePath>../pom.xml</relativePath> is not really necessary as it's the default value).

(旁白:< relativePath > . . / pom。xml实际上并不是必需的,因为它是默认值)。