构建maven项目会导致错误

时间:2016-01-20 07:40:37

标签: java eclipse 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 构建核心行程时,我收到以下错误:

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)

请帮助我解决此问题

1 个答案:

答案 0 :(得分:0)

答案很简单,请运行:

mvn clean install
来自顶级父项目的

(在您的示例中名为core)。

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

编辑:啊,我明白了,
您的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>