Java MavenError:无法在项目上执行目标:无法解决Maven Multimodule项目中的依赖关系
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24673671/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
MavenError: Failed to execute goal on project: Could not resolve dependencies In Maven Multimodule project
提问by Harmeet Singh Taara
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
:
我正在尝试创建一个 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.
我正在尝试从网络查找解决方案,但仍然没有找到解决方案。在 Eclipse 中,当我打开Dependency Hierarchy
of service 模块时,它将 DAO 模块显示为文件夹而不是 jar。下面是Dependency Hierarchy
服务模块的屏幕截图。
回答by declension
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 Reactorcan't collect the necessary dependencies to build the submodule.
如果有人回到这个问题,我认为这里的问题是未能首先安装所有这些子模块所依赖的父 pom,因此Maven Reactor无法收集构建子模块所需的依赖项。
So from the root directory (here D:\luna_workspace\empire_club\empirecl
) it probably just needs a:
所以从根目录(这里D:\luna_workspace\empire_club\empirecl
)它可能只需要一个:
mvn clean install
(Aside: <relativePath>../pom.xml</relativePath>
is not really necessary as it's the default value).
(旁白:<relativePath>../pom.xml</relativePath>
并不是真的有必要,因为它是默认值)。
回答by Sultan1991
In my case I forgot it was packaging conflict jar vs pom. I forgot to write
就我而言,我忘记了它是包装冲突 jar 与 pom。我忘记写了
<packaging>pom</packaging>
In every child pom.xml file
在每个子 pom.xml 文件中
回答by WounderGrifft
My solution was to insert <packaging>pom</packaging>
between artifactId
and version
我的解决方案是<packaging>pom</packaging>
在artifactId
和之间插入version
<groupId>com.onlinechat</groupId>
<artifactId>chat-online</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<modules>
<module>server</module>
<module>client</module>
<module>network</module>
</modules>
回答by Tolga A
My solution:
我的解决方案:
- remove all projects in current workspace
- import all again
- maven update project (Alt + F5) -> Select Alland check Force Update of Snapshots/Releases
- maven build (Ctrl + B) until there is nothing to build
- 删除当前工作区中的所有项目
- 再次导入所有
- maven 更新项目 (Alt + F5) ->全选并检查快照/发布的强制更新
- maven build (Ctrl + B) 直到没有东西可以构建
It worked for me after the second try.
第二次尝试后它对我有用。