[英]Building maven project causes error
嗨,我正在使用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構建core- itinerary時,出現以下錯誤:
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)
請幫助我解決該問題
答案很簡單,請運行:
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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.