2013-06-18 147 views
4

我有一個多模塊maven項目,我無法編譯。我有一個Nexus倉庫位於我的本地網絡上,它正在工作(IntelliJ Idea能夠解決僅駐留在該倉庫中的依賴項),並且我正在通過Jetbrains TeamCity進行構建。我非常確定TeamCity正在工作,因爲我已經設置的其他幾個構建配置仍然有效(使用相同的settings.xml)。對於可能導致此問題的原因,我有點不知所措。這裏是我的POM文件:Maven多模塊項目,不解決依賴

父POM:

<?xml version="1.0" encoding="UTF-8"?> 
<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.company.product.plugins</groupId> 
    <artifactId>plugin-parent</artifactId> 
    <version>1.2-SNAPSHOT</version> 
    <packaging>pom</packaging> 

    <modules> 
     <module>product-wireless-plugin</module> 
     <module>product-paging-plugin</module> 
    </modules> 

    <distributionManagement> 
     <repository> 
      <id>releases</id> 
      <url>http://192.168.2.192:8081/nexus/content/repositories/releases/</url> 
     </repository> 
     <snapshotRepository> 
      <id>snapshots</id> 
      <url>http://192.168.2.192:8081/nexus/content/repositories/snapshots</url> 
     </snapshotRepository> 
    </distributionManagement> 

    <pluginRepositories> 
     <pluginRepository> 
      <id>autoincrement-versions-maven-plugin</id> 
      <name>autoincrement-versions-maven-plugin</name> 
      <url>http://autoincrement-versions-maven-plugin.googlecode.com/svn/repo</url> 
      <snapshots> 
       <enabled>true</enabled> 
      </snapshots> 
     </pluginRepository> 
    </pluginRepositories> 

    <build> 
     <plugins> 
      <plugin> 
       <groupId>org.codehaus.mojo</groupId> 
       <artifactId>autoincrement-versions-maven-plugin</artifactId> 
       <version>2.0-SNAPSHOT</version> 
       <executions> 
        <execution> 
         <id>update-pom-versions</id> 
         <goals> 
          <goal>increment</goal> 
          <goal>commit</goal> 
         </goals> 
         <phase>compile</phase> 
         <configuration> 
          <autoIncrementVersion>true</autoIncrementVersion> 
         </configuration> 
        </execution> 
       </executions> 
      </plugin> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-surefire-plugin</artifactId> 
       <configuration> 
        <testFailureIgnore>true</testFailureIgnore> 
       </configuration> 
      </plugin> 
     </plugins> 
    </build> 

</project> 

產品無線POM:

<?xml version="1.0" encoding="UTF-8"?> 
<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"> 
    <parent> 
     <artifactId>plugin-parent</artifactId> 
     <groupId>com.company.product.plugins</groupId> 
     <version>1.2-SNAPSHOT</version> 
    </parent> 
    <modelVersion>4.0.0</modelVersion> 

    <groupId>com.company.product.plugins</groupId> 
    <artifactId>product-wireless-plugin</artifactId> 
    <version>0.1.2</version> 

    <distributionManagement> 
     <repository> 
      <id>releases</id> 
      <url>http://192.168.2.192:8081/nexus/content/repositories/releases/</url> 
     </repository> 
     <snapshotRepository> 
      <id>snapshots</id> 
      <url>http://192.168.2.192:8081/nexus/content/repositories/snapshots</url> 
     </snapshotRepository> 
    </distributionManagement> 

    <dependencies> 
     <dependency> 
      <groupId>com.company.product</groupId> 
      <artifactId>product-common</artifactId> 
      <version>0.9.1</version> 
     </dependency> 
    </dependencies> 

</project> 

產品分頁POM:

<?xml version="1.0" encoding="UTF-8"?> 
<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"> 
    <parent> 
     <artifactId>plugin-parent</artifactId> 
     <groupId>com.company.product.plugins</groupId> 
     <version>1.2-SNAPSHOT</version> 
    </parent> 
    <modelVersion>4.0.0</modelVersion> 

    <groupId>com.company.product.plugins</groupId> 
    <artifactId>product-paging-plugin</artifactId> 
    <version>0.1.2</version> 

    <distributionManagement> 
     <repository> 
      <id>releases</id> 
      <url>http://192.168.2.192:8081/nexus/content/repositories/releases/</url> 
     </repository> 
     <snapshotRepository> 
      <id>snapshots</id> 
      <url>http://192.168.2.192:8081/nexus/content/repositories/snapshots</url> 
     </snapshotRepository> 
    </distributionManagement> 

    <dependencies> 
     <dependency> 
      <groupId>com.company.product</groupId> 
      <artifactId>product-common</artifactId> 
      <version>0.9.1</version> 
     </dependency> 
    </dependencies> 

</project> 

而且我得到的錯誤是:

com.company.product.plugins:product-wireless-plugin [13:54:16] [com.company.product.plugins:product-wireless-plugin]從'C:/ TeamCity/buildAgent/work導入數據/40ac813105cf8bd7/product-wireless-plugin/target/surefire-reports/TEST-*.xml'with'surefire'processor [13:54:16] [com.company.product.plugins:product-wireless-plugin] Surefire報告觀察者 [13:54:16] [com.company.product.plugins:product-wireless-plugin]下載:repolocation/nexus/content/groups/public/com/company/product/product-parent/0.9.0 /product-parent-0.9.0.pom [13:54:16] [com.company.product.plugins:product-wireless-plugin]無法執行項目product-wireless-plugin的目標:無法解析依賴關係項目com.company.product.plugins:product-wireless-plugin:jar:0.1.2:無法收集[com.company.prod uct:product-common:jar:0.9.1(compile)]

我在試圖調試時遇到了相當的損失...有沒有人有任何建議?

+0

1)對於這種「無法解析的依賴」的錯誤,幾乎總是在構建日誌中更早的更詳細的錯誤消息和/或堆棧跟蹤。 2)用'-X'標誌重新運行構建。 – noahlz

+0

@noahlz如果你可以發表你的評論作爲答案,我會接受它。我能夠使用該調試方法找到問題。 –

回答

7

有幾種解決這類問題的方法/工具。

  1. 對於這種「無法解析的依賴」的錯誤,幾乎總會有一個更詳細的錯誤信息和/或在更早的構建日誌堆棧跟蹤。 Maven日誌實際上非常冗長,以至於不得不從構建失敗的幾個屏幕上搜索「根」錯誤消息。

  2. -X標誌重新運行構建。這裏是documentation of Maven command line switches

  3. 另一個選擇是使用mvn dependency:tree來檢查傳遞依賴關係的完整圖。 mvn help:effective-pom是另一種有用的工具,考慮到你的settings.xml,任何活動的配置文件後,打印出的pom.xml等。同樣mvn help:active-profiles

0

您的多模塊構建中存在很多問題。其中最重要的是您定義的依賴性:

<dependencies> 
    <dependency> 
     <groupId>com.company.product</groupId> 
     <artifactId>product-common</artifactId> 
     <version>0.9.1</version> 
    </dependency> 
</dependencies> 

這似乎不是沒有在庫中現有的或者你沒有訪問包含它還是你的下載已經無論基於何種原因失敗庫(罐」猜猜!)。你是否在使用像Artifactory,Nexus,Archiva這樣的資源庫管理器?如果不是,我建議開始使用一個。

除了您正在使用不同版本的父母和無線模塊的模塊:

<parent> 
     <artifactId>plugin-parent</artifactId> 
     <groupId>com.company.product.plugins</groupId> 
     <version>1.2-SNAPSHOT</version> 
    </parent> 
    <modelVersion>4.0.0</modelVersion> 

    <groupId>com.company.product.plugins</groupId> 
    <artifactId>product-wireless-plugin</artifactId> 
    <version>0.1.2</version> 

多模塊裝配只能通過父定義版本和這意味着神器內上面應該看起來像這樣:

<modelVersion>4.0.0</modelVersion> 
<parent> 
    <artifactId>plugin-parent</artifactId> 
    <groupId>com.company.product.plugins</groupId> 
    <version>1.2-SNAPSHOT</version> 
</parent> 

<groupId>com.company.product.plugins</groupId> 
<artifactId>product-wireless-plugin</artifactId> 

該模塊不應該定義一個版本本身,因爲它會繼承它從父。此外,您可以看到您有一個定義發行版本(1.2)的模塊,而父代定義了SNAPSHOT版本。正在開發的應用程序/模塊應該定義一個SNAPSHOT版本的版本,這意味着像1.2-SNAPSHOT等。

對於distributionManagement的定義也相應地適用。這應該只在項目的父項中定義一次。

順便說一句。如果你有幾個項目,最好是定義一個公司父母,其中包含一些默認的定義,如distributionManagement,pluginManagement,dependencyManagement等。

+0

我不同意你關於兒童和父母之間的版本需求相同,因爲這實際上是我的問題的原因。圖書館「產品共同」有一個父母。我已經保留了主pom和所有孩子poms之間的主版本號。但是,我偶爾需要發佈一個更新,以便修正一個錯誤,並且增加父級的所有子庫的版本都沒有任何意義。版本號碼級聯。如果我在子pom中有版本號,它會覆蓋父級版本。 –

+0

另外,downvote是因爲沒有正確地閱讀問題,因爲問題確實提到了我的Nexus存儲庫以及圖書館通過我的回購解決這一事實。 –

2

好的,我已經通過@noahlz的輸入解決了這個問題。在使用-X標誌調試我的構建之後,我發現無法找到「product-common」(product-parent)的父pom。在瀏覽我的Sonatype Nexus存儲庫後,我發現我的構建系統僅在發佈新模塊時才發佈父pom的新版本。所以,即使我的父pom版本是0.9.0,版本庫的最新版本爲0.6.1。我猜想「產品通用」庫正在編譯,因爲它可以在編譯時訪問父目錄(使用0.9.0版本號)。無論哪種方式,將「product-common」中的父pom版本更改爲指向存儲庫中的最新版本,可以解決構建插件問題。

相關問題