Maven在存储库中复制了jar

时间:2012-09-21 18:22:40

标签: maven james

由于我的存储库中存在重复的jar,我收到了重复的类错误。 Jars随附一个开源Apache项目的子模块的pom,项目为James,子模块为container-spring

以下是James根目录中的pom.xml:

http://svn.apache.org/repos/asf/james/server/tags/james-server-3.0-beta4/pom.xml

这是子模块container-spring的pom.xml:

http://svn.apache.org/repos/asf/james/server/tags/james-server-3.0-beta4/container-spring/pom.xml

2 个答案:

答案 0 :(得分:3)

您应该在主jar的依赖关系声明中指定要排除的子项目对应的jar。

有关如何定义依赖项排除的详细信息,请参阅maven documentation

答案 1 :(得分:3)

要回答您的问题,我使用以下pom.xml配置了一个简单的maven项目:

<project>
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.stackoverflow.tuxi</groupId>
  <artifactId>duplicatedjar</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>jar</packaging>

  <dependencies>
    <dependency>
      <groupId>org.apache.james</groupId>
      <artifactId>james-server</artifactId>
      <version>3.0-beta4</version>
      <type>pom</type>
    </dependency>
    <dependency>
      <groupId>org.apache.james</groupId>
      <artifactId>james-server-container-spring</artifactId>
      <version>3.0-beta4</version>
    </dependency>
  </dependencies>
</project>

然后执行 maven dependency tree 命令来分析依赖项:

% mvn dependency:tree                                                                                                                                                                                              
[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building duplicatedjar 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-dependency-plugin:2.1:tree (default-cli) @ duplicatedjar ---
[INFO] com.stackoverflow.tuxi:duplicatedjar:jar:1.0-SNAPSHOT
[INFO] +- org.apache.james:james-server:pom:3.0-beta4:compile
[INFO] \- org.apache.james:james-server-container-spring:jar:3.0-beta4:compile
[INFO]    +- org.apache.james:james-server-lifecycle-spring:jar:3.0-beta4:compile
[INFO]    |  +- org.apache.geronimo.specs:geronimo-annotation_1.1_spec:jar:1.0.1:compile
[INFO]    |  \- org.apache.geronimo.specs:geronimo-jpa_2.0_spec:jar:1.0:compile
[INFO]    +- org.apache.james:james-server-lifecycle-api:jar:3.0-beta4:compile
[INFO]    +- org.apache.james:james-server-filesystem-api:jar:3.0-beta4:compile
[INFO]    |  +- org.apache.james:apache-jsieve-manager-api:jar:0.5:compile
[INFO]    |  \- commons-io:commons-io:jar:2.0.1:compile
[INFO]    +- org.apache.james:james-server-mailetcontainer-api:jar:3.0-beta4:compile
[INFO]    +- org.apache.james:james-server-protocols-library:jar:3.0-beta4:compile
[INFO]    |  +- org.apache.james:james-server-util:jar:3.0-beta4:compile
[INFO]    |  +- org.apache.james.protocols:protocols-netty:jar:1.6.2:compile
[INFO]    |  \- io.netty:netty:jar:3.3.1.Final:compile
[INFO]    +- org.apache.james:james-server-data-api:jar:3.0-beta4:compile
[INFO]    +- org.apache.james:james-server-core:jar:3.0-beta4:compile
[INFO]    |  \- org.apache.james:apache-mailet-base:jar:1.1:compile
[INFO]    +- org.apache.james:apache-james-mailbox-api:jar:0.4:compile
[INFO]    +- org.apache.james:apache-james-mailbox-tool:jar:0.4:compile
[INFO]    |  +- org.apache.james:apache-james-mailbox-store:jar:0.4:compile
[INFO]    |  |  +- org.apache.james:apache-mime4j-core:jar:0.7.2:compile
[INFO]    |  |  \- org.apache.james:apache-mime4j-dom:jar:0.7.2:compile
[INFO]    |  +- org.apache.james:apache-james-mailbox-memory:jar:0.4:compile
[INFO]    |  +- org.apache.geronimo.specs:geronimo-annotation_1.0_spec:jar:1.1.1:compile
[INFO]    |  \- org.apache.openjpa:openjpa:jar:2.1.0:compile
[INFO]    |     +- net.sourceforge.serp:serp:jar:1.13.1:compile
[INFO]    |     |  \- junit:junit:jar:3.8.1:compile
[INFO]    |     +- org.apache.geronimo.specs:geronimo-jms_1.1_spec:jar:1.1.1:compile
[INFO]    |     +- org.apache.geronimo.specs:geronimo-jta_1.1_spec:jar:1.1.1:compile
[INFO]    |     \- commons-pool:commons-pool:jar:1.5.4:compile
[INFO]    +- org.apache.james.protocols:protocols-api:jar:1.6.2:compile
[INFO]    +- org.apache.james:apache-mailet:jar:2.4:compile
[INFO]    +- org.springframework:spring-core:jar:3.1.0.RELEASE:compile
[INFO]    |  +- org.springframework:spring-asm:jar:3.1.0.RELEASE:compile
[INFO]    |  \- commons-logging:commons-logging:jar:1.1.1:compile
[INFO]    +- org.springframework:spring-beans:jar:3.1.0.RELEASE:compile
[INFO]    +- org.springframework:spring-context:jar:3.1.0.RELEASE:compile
[INFO]    |  +- org.springframework:spring-aop:jar:3.1.0.RELEASE:compile
[INFO]    |  \- org.springframework:spring-expression:jar:3.1.0.RELEASE:compile
[INFO]    +- org.springframework:spring-web:jar:3.1.0.RELEASE:compile
[INFO]    |  \- aopalliance:aopalliance:jar:1.0:compile
[INFO]    +- org.springframework.osgi:spring-osgi-extender:jar:1.2.1:compile
[INFO]    |  +- org.springframework.osgi:spring-osgi-core:jar:1.2.1:compile
[INFO]    |  |  +- org.springframework:org.springframework.aop:jar:2.5.6.SEC01:compile
[INFO]    |  |  |  \- org.aopalliance:com.springsource.org.aopalliance:jar:1.0.0:compile
[INFO]    |  |  +- org.springframework:org.springframework.beans:jar:2.5.6.SEC01:compile
[INFO]    |  |  +- org.springframework:org.springframework.context:jar:2.5.6.SEC01:compile
[INFO]    |  |  \- org.springframework:org.springframework.core:jar:2.5.6.SEC01:compile
[INFO]    |  \- org.springframework.osgi:spring-osgi-io:jar:1.2.1:compile
[INFO]    +- org.osgi:org.osgi.core:jar:4.2.0:compile
[INFO]    +- commons-configuration:commons-configuration:jar:1.6:compile
[INFO]    |  +- commons-collections:commons-collections:jar:3.2.1:compile
[INFO]    |  \- commons-lang:commons-lang:jar:2.4:compile
[INFO]    +- org.slf4j:slf4j-api:jar:1.6.1:compile
[INFO]    +- javax.mail:mail:jar:1.4.4:compile
[INFO]    \- log4j:log4j:jar:1.2.16:compile
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.140s
[INFO] Finished at: Sun Sep 30 12:30:30 BRT 2012
[INFO] Final Memory: 12M/169M
[INFO] ------------------------------------------------------------------------

我不知道你项目中的哪些罐子与上面的罐子有冲突但是我注意到spring依赖性取决于 apache commons suite (commons-xxx deps)。很多项目都使用它们(I.M.O.很多东西应该包含在JDK本身,但那是另一个线程)但是一些公共库存在一些问题:

  • 向后兼容性问题
  • 这些年来,groupid和artifactid发生了变化,所以你 最终可以使用不同名称的平等罐子(commons-xxx和 org.apache.commons.xxx)

实际上,与apache commons套件存在冲突的依赖是很正常的,所以我在这里猜测这是你的实际问题。

通常,解决方法是直接在依赖项中声明项目中需要的apache commons libs,并在依赖项部分中排除冲突库,如@Vikdor所说

你最终会得到类似的东西(重要的是只删除相互冲突的,而不是像下面的例子中那样,或者你的软件无法正常工作):< / p>

<project>
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.stackoverflow.tuxi</groupId>
  <artifactId>duplicatedjar</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>jar</packaging>

  <dependencies>
    <dependency>
      <groupId>org.apache.james</groupId>
      <artifactId>james-server</artifactId>
      <version>3.0-beta4</version>
      <type>pom</type>
    </dependency>
    <dependency>
      <groupId>org.apache.james</groupId>
      <artifactId>james-server-container-spring</artifactId>
      <version>3.0-beta4</version>
      <!-- DO NOT exclude all of them, only the conflicting ones -->
      <exclusions>
        <exclusion>
          <groupId>commons-io</groupId>
          <artifactId>commons-io</artifactId>
        </exclusion>
        <exclusion>
          <groupId>commons-pool</groupId>
          <artifactId>commons-pool</artifactId>
        </exclusion>
        <exclusion>
          <groupId>commons-logging</groupId>
          <artifactId>commons-logging</artifactId>
        </exclusion>
        <exclusion>
          <groupId>commons-collections</groupId>
          <artifactId>commons-collections</artifactId>
        </exclusion>
        <exclusion>
          <groupId>commons-lang</groupId>
          <artifactId>commons-lang</artifactId>
        </exclusion>
      </exclusions>
    </dependency>
  </dependencies>
</project>