MavenError:无法在项目上执行目标:无法解析Maven多模块项目中的依赖项 [英] MavenError: Failed to execute goal on project: Could not resolve dependencies In Maven Multimodule project

查看:689
本文介绍了MavenError:无法在项目上执行目标:无法解析Maven多模块项目中的依赖项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个Maven多模块项目。该项目已成功创建,但是当我尝试使用一个模块作为另一个模块的依赖项时,它将引发异常。当我使用eclipse创建模块时,我将包装选择为jar,但是创建模块时,子pom.xml中未提及包装标签,因此我手动将包装标签插入jar。以下是我的父母 pom.xml

I am trying to create a maven multi-module project. the project is created successfully but when I am trying to use one module as a dependency of another module, it throws an exception. When I create a module using eclipse, I was selecting packaging as a jar, but when the module is created, 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:

<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子模块:

<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>
------------------------

服务子模块:

<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>
------------------------------------------

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

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

[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上收集依赖项正在尝试从Web查找解决方案,但仍未找到解决方案。在Eclipse中,当我打开服务模块的 Dependency Hierarchy 时,它显示DAO模块为一个文件夹而不是jar。下面是服务模块的依赖关系层次结构的屏幕截图。

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.

推荐答案

万一有人回到这个问题,我认为这里的问题是所有这些子模块都依赖于它的父pom首先无法安装,所以 Maven Reactor 无法收集必要的内容

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.

因此从根目录(这里 D:\luna_workspace\empire_club\empirecl )它可能只需要一个:

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

mvn clean install

(除了:< relativePath> ../ pom.xml< / relativePath> 这是默认值)。

这篇关于MavenError:无法在项目上执行目标:无法解析Maven多模块项目中的依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆