2013-06-18 77 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版本更改为指向存储库中的最新版本,可以解决构建插件问题。

相关问题