2016-01-20 90 views
0

嗨我正在建设我的项目使用MAVEN,我的项目结构是这样的。建设maven项目导致错误

core 
    core-contact 
    address 
    phone 
    core - itinerary 

一块的每个模块pom.xml文件的代码如下

芯:pom.xml的

 <groupId>ginfo.core</groupId> 
     <artifactId>core</artifactId> 
     <name>${productBrand} - Core POM</name> 
     <packaging>pom</packaging> 
     <version>1.1</version> 
     <modules> 
     <module>Contact</module> 
     <module>Itinerary</module> 
     </modules> 

地址:pom.xml的

 <parent> 
      <groupId>ginfo.core</groupId> 
      <artifactId>core-contact</artifactId> 
      <version>1.1</version> 
      <relativePath>../pom.xml</relativePath> 
     </parent> 
      <artifactId>core-address</artifactId> 
      <name>${productBrand} - core-address</name> 
      <packaging>jar</packaging> 

电话:pom.xml的

  <parent> 
      <groupId>ginfo.core</groupId> 
      <artifactId>core-contact</artifactId> 
      <version>1.1</version> 
      <relativePath>../pom.xml</relativePath> 
      </parent> 

     <artifactId>core-phone</artifactId> 
     <name>${productBrand} - core-phone</name> 
     <packaging>jar</packaging> 

核心行程:pom.xml中

<parent> 
     <groupId>ginfo.core</groupId> 
     <artifactId>core</artifactId> 
     <version>1.1</version> 
     <relativePath>../pom.xml</relativePath> 
    </parent> 
    <artifactId>core-itinerary</artifactId> 
    <name>${productBrand} - core-itinerary</name> 
    <packaging>jar</packaging> 

    <description> 
     ${productBrand} - core-itinerary 
    </description> 
    <dependencies> 
     <dependency> 
     <groupId>ginfo.core</groupId> 
     <artifactId>core-contact</artifactId> 
     <version>1.1</version> 
     </dependency> 

核心接触:pom.xml中

 <parent> 
     <groupId>ginfo.core</groupId> 
     <artifactId>core</artifactId> 
     <version>1.1</version> 
     <relativePath>../pom.xml</relativePath> 
     </parent> 

    <artifactId>core-contact</artifactId> 
    <name>${productBrand} - core-contact</name> 
    <packaging>pom</packaging> 

    <description> 
     ${productBrand} - core-contact 
    </description> 
    <modules> 
     <module>Address</module> 
     <module>Phone</module> 
    </modules> 

当我试图使用mvn clean install构建核心行程我是ge拟合以下错误:

Failed to execute goal on project core-itinerary: could not resolve dependancies for project ginfo.core : core-itinerary: jar 1.1: could not find artifact ginfo.core : core-contact.jar : 1.1 in mvnrepository (http://repo1.maven.org/maven2)

请帮我如何解决这个问题

+0

'address'和'phone'被引用'核心contact'其父 - 在哪里为一个POM? –

+0

请使用编辑链接并将其添加到您的问题而不是评论。 –

回答

0

答案很简单,请运行:

mvn clean install 
从顶部父项目

(它是在你的例子中命名为core)。

错误背后的原因:could not resolve dependencies缺少依赖模块的首先构建/安装。并提到上述解决方案,将建立&以正确的顺序安装所需的模块。


编辑:啊我看,
core-contact采用POM包装(<packaging>pom</packaging>),但里面core-itinerary/pom.xml你有以下依赖性:

<dependency> 
    <groupId>ginfo.core</groupId> 
    <artifactId>core-contact</artifactId> 
    <version>1.1</version> 
</dependency> 

因为上面的条目还没有指定<type>pom</type> ,所以maven认为它是<type>jar</type>(默认值),这当然不能反映现实。
使它工作,请更改为:

<dependency> 
    <groupId>ginfo.core</groupId> 
    <artifactId>core-contact</artifactId> 
    <version>1.1</version> 
    <type>pom</type>  <!-- crucial line --> 
</dependency> 
+0

我在“核心”处运行“mvn clean install”,但出现以下错误:未能在项目core-itinerary上执行目标:无法解析项目ginfo.core:core-itinerary:jar:1的依赖项。1;无法找到ginfo.core:core-contact:jar:1.1中的http://repo1.maven.org/maven2缓存在本地存储库解析中,直到mvnrepository的更新时间间隔已过或更新才会重新尝试 –

+0

core-1.1没有正确安装..确保它存在于.m2/repository/path_to_your_core_jar/ ...(假设你的maven repo在默认路径中) – madhairsilence

+1

很好的答案。非常感谢你。添加行 pom工作得很好。挣扎了很多时间来解决这个问题。 –