热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

maven多个父依赖中jar包冲突解决办法

在jenkins插件开发的过程中,maven父项目基本是plugin   在红箭头标记的地方,这两个地方是指定了父项目中一些依赖的版本,但是这两个依赖版本中,各自依赖的一些jar包

在jenkins插件开发的过程中,maven父项目基本是plugin

maven 多个父依赖中jar包冲突解决办法

 

 

 在红箭头标记的地方,这两个地方是指定了父项目中一些依赖的版本,但是这两个依赖版本中,各自依赖的一些jar包很可能会有冲突,这时候,使用exclude 也无法使用。compile时会有如下错误:

[WARNING] Rule 4: org.apache.maven.plugins.enforcer.RequireUpperBoundDeps failed with message:
Failed while enforcing RequireUpperBoundDeps. The error(s) are [
Require upper bound dependencies error for org.eclipse.jetty:jetty-io:9.2.12.v20150709 paths to dependency are:
+-com.ztbsuper:dingding-notifications:1.11-SNAPSHOT
  +-org.jenkins-ci.main:jenkins-test-harness:2.13
    +-org.jenkins-ci.main:jenkins-test-harness-htmlunit:2.18-1
      +-org.eclipse.jetty:jetty-io:9.2.12.v20150709
and
+-com.ztbsuper:dingding-notifications:1.11-SNAPSHOT
  +-org.jenkins-ci.main:jenkins-test-harness:2.13
    +-org.eclipse.jetty:jetty-security:9.2.15.v20160210
      +-org.eclipse.jetty:jetty-server:9.2.15.v20160210
        +-org.eclipse.jetty:jetty-io:9.2.12.v20150709 (managed) <-- org.eclipse.jetty:jetty-io:9.2.15.v20160210
and
+-com.ztbsuper:dingding-notifications:1.11-SNAPSHOT
  +-org.jenkins-ci.main:jenkins-test-harness:2.13
    +-org.jenkins-ci.main:jenkins-test-harness-htmlunit:2.18-1
      +-org.eclipse.jetty.websocket:websocket-client:9.2.12.v20150709
        +-org.eclipse.jetty:jetty-io:9.2.12.v20150709 (managed) <-- org.eclipse.jetty:jetty-io:9.2.15.v20160210
and
+-com.ztbsuper:dingding-notifications:1.11-SNAPSHOT
  +-org.jenkins-ci.main:jenkins-test-harness:2.13
    +-org.jenkins-ci.main:jenkins-test-harness-htmlunit:2.18-1
      +-org.eclipse.jetty.websocket:websocket-common:9.2.12.v20150709
        +-org.eclipse.jetty:jetty-io:9.2.12.v20150709 (managed) <-- org.eclipse.jetty:jetty-io:9.2.15.v20160210
, 
Require upper bound dependencies error for org.codehaus.plexus:plexus-utils:2.1 paths to dependency are:
+-com.ztbsuper:dingding-notifications:1.11-SNAPSHOT
  +-org.jenkins-ci.main:jenkins-test-harness:2.13
    +-org.eclipse.sisu:org.eclipse.sisu.plexus:0.1.0
      +-org.codehaus.plexus:plexus-utils:2.1
and
+-com.ztbsuper:dingding-notifications:1.11-SNAPSHOT
  +-org.jenkins-ci.main:jenkins-test-harness:2.13
    +-org.jenkins-ci.lib:lib-jenkins-maven-embedder:3.11
      +-org.apache.maven:maven-core:3.1.0
        +-org.codehaus.plexus:plexus-utils:2.1 (managed) <-- org.codehaus.plexus:plexus-utils:3.0.8
and
+-com.ztbsuper:dingding-notifications:1.11-SNAPSHOT
  +-org.jenkins-ci.main:jenkins-test-harness:2.13
    +-org.jenkins-ci.lib:lib-jenkins-maven-embedder:3.11
      +-org.apache.maven:maven-artifact:3.1.0
        +-org.codehaus.plexus:plexus-utils:2.1 (managed) <-- org.codehaus.plexus:plexus-utils:3.0.10
and
+-com.ztbsuper:dingding-notifications:1.11-SNAPSHOT
  +-org.jenkins-ci.main:jenkins-test-harness:2.13
    +-org.jenkins-ci.lib:lib-jenkins-maven-embedder:3.11
      +-org.apache.maven:maven-compat:3.1.0
        +-org.codehaus.plexus:plexus-utils:2.1 (managed) <-- org.codehaus.plexus:plexus-utils:3.0.10
and
+-com.ztbsuper:dingding-notifications:1.11-SNAPSHOT
  +-org.jenkins-ci.main:jenkins-test-harness:2.13
    +-org.jenkins-ci.lib:lib-jenkins-maven-embedder:3.11
      +-org.apache.maven:maven-embedder:3.1.0
        +-org.codehaus.plexus:plexus-utils:2.1 (managed) <-- org.codehaus.plexus:plexus-utils:3.0.10
and
+-com.ztbsuper:dingding-notifications:1.11-SNAPSHOT
  +-org.jenkins-ci.main:jenkins-test-harness:2.13
    +-org.jenkins-ci.lib:lib-jenkins-maven-embedder:3.11
      +-org.apache.maven:maven-aether-provider:3.1.0
        +-org.codehaus.plexus:plexus-utils:2.1 (managed) <-- org.codehaus.plexus:plexus-utils:3.0.10
and
+-com.ztbsuper:dingding-notifications:1.11-SNAPSHOT
  +-org.jenkins-ci.main:jenkins-test-harness:2.13
    +-org.jenkins-ci.lib:lib-jenkins-maven-embedder:3.11
      +-org.apache.maven.wagon:wagon-provider-api:2.4
        +-org.codehaus.plexus:plexus-utils:2.1 (managed) <-- org.codehaus.plexus:plexus-utils:3.0.8
and
+-com.ztbsuper:dingding-notifications:1.11-SNAPSHOT
  +-org.jenkins-ci.main:jenkins-test-harness:2.13
    +-org.jenkins-ci.lib:lib-jenkins-maven-embedder:3.11
      +-org.apache.maven:maven-core:3.1.0
        +-org.apache.maven:maven-model:3.1.0
          +-org.codehaus.plexus:plexus-utils:2.1 (managed) <-- org.codehaus.plexus:plexus-utils:3.0.10
and
+-com.ztbsuper:dingding-notifications:1.11-SNAPSHOT
  +-org.jenkins-ci.main:jenkins-test-harness:2.13
    +-org.jenkins-ci.lib:lib-jenkins-maven-embedder:3.11
      +-org.apache.maven:maven-core:3.1.0
        +-org.apache.maven:maven-settings:3.1.0
          +-org.codehaus.plexus:plexus-utils:2.1 (managed) <-- org.codehaus.plexus:plexus-utils:3.0.10
and
+-com.ztbsuper:dingding-notifications:1.11-SNAPSHOT
  +-org.jenkins-ci.main:jenkins-test-harness:2.13
    +-org.jenkins-ci.lib:lib-jenkins-maven-embedder:3.11
      +-org.apache.maven:maven-core:3.1.0
        +-org.apache.maven:maven-settings-builder:3.1.0
          +-org.codehaus.plexus:plexus-utils:2.1 (managed) <-- org.codehaus.plexus:plexus-utils:3.0.10
and
+-com.ztbsuper:dingding-notifications:1.11-SNAPSHOT
  +-org.jenkins-ci.main:jenkins-test-harness:2.13
    +-org.jenkins-ci.lib:lib-jenkins-maven-embedder:3.11
      +-org.apache.maven:maven-core:3.1.0
        +-org.apache.maven:maven-repository-metadata:3.1.0
          +-org.codehaus.plexus:plexus-utils:2.1 (managed) <-- org.codehaus.plexus:plexus-utils:3.0.10
and
+-com.ztbsuper:dingding-notifications:1.11-SNAPSHOT
  +-org.jenkins-ci.main:jenkins-test-harness:2.13
    +-org.jenkins-ci.lib:lib-jenkins-maven-embedder:3.11
      +-org.apache.maven:maven-core:3.1.0
        +-org.apache.maven:maven-model-builder:3.1.0
          +-org.codehaus.plexus:plexus-utils:2.1 (managed) <-- org.codehaus.plexus:plexus-utils:3.0.10
and
+-com.ztbsuper:dingding-notifications:1.11-SNAPSHOT
  +-org.jenkins-ci.main:jenkins-test-harness:2.13
    +-org.jenkins-ci.lib:lib-jenkins-maven-embedder:3.11
      +-org.apache.maven:maven-core:3.1.0
        +-org.sonatype.plexus:plexus-sec-dispatcher:1.3
          +-org.codehaus.plexus:plexus-utils:2.1 (managed) <-- org.codehaus.plexus:plexus-utils:1.5.5
, 
Require upper bound dependencies error for org.codehaus.plexus:plexus-classworlds:2.4 paths to dependency are:
+-com.ztbsuper:dingding-notifications:1.11-SNAPSHOT
  +-org.jenkins-ci.main:jenkins-test-harness:2.13
    +-org.eclipse.sisu:org.eclipse.sisu.plexus:0.1.0
      +-org.codehaus.plexus:plexus-classworlds:2.4
and
+-com.ztbsuper:dingding-notifications:1.11-SNAPSHOT
  +-org.jenkins-ci.main:jenkins-test-harness:2.13
    +-org.jenkins-ci.lib:lib-jenkins-maven-embedder:3.11
      +-org.apache.maven:maven-core:3.1.0
        +-org.codehaus.plexus:plexus-classworlds:2.4.2
and
+-com.ztbsuper:dingding-notifications:1.11-SNAPSHOT
  +-org.jenkins-ci.main:jenkins-test-harness:2.13
    +-org.jenkins-ci.lib:lib-jenkins-maven-embedder:3.11
      +-org.apache.maven:maven-embedder:3.1.0
        +-org.codehaus.plexus:plexus-classworlds:2.4.2
]
[INFO] ------------------------------------------------------------------------

按照我之前一篇排除jar包冲突办法,找到类似:Require upper bound dependencies error for org.eclipse.jetty:jetty-io:9.2.12.v20150709 paths to dependency are:   这句话定位到所冲突的jar包。

这里以jetty-io  jar包为例。

maven 多个父依赖中jar包冲突解决办法

 

 

可以看到 这个jar包在项目里有两个版本号,是在  jenkins-test-harness   里,这个就是我们引入的plugin 父模块中的,此时exclude也不好使,那么办法是使用   dependencyManagement  这个标签来锁定一些jar包的版本,部分配置如下:


    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.apache.antgroupId>
                <artifactId>antartifactId>
                <version>1.9.2version>
            dependency>
            <dependency>
                <groupId>org.eclipse.jettygroupId>
                <artifactId>jetty-utilartifactId>
                <version>9.2.15.v20160210version>
            dependency>
            <dependency>
                <groupId>org.eclipse.jettygroupId>
                <artifactId>jetty-ioartifactId>
                <version>9.2.12.v20150709version>
            dependency>
            <dependency>
                <groupId>org.codehaus.plexusgroupId>
                <artifactId>plexus-utilsartifactId>
                <version>2.1version>
            dependency>
        dependencies>
    dependencyManagement>

然后再次compile

Failed while enforcing RequireUpperBoundDeps. The error(s) are [
Require upper bound dependencies error for org.eclipse.jetty:jetty-io:9.2.12.v20150709 paths to dependency are:
+-com.ztbsuper:dingding-notifications:1.11-SNAPSHOT
  +-org.jenkins-ci.main:jenkins-test-harness:2.13
    +-org.jenkins-ci.main:jenkins-test-harness-htmlunit:2.18-1
      +-org.eclipse.jetty:jetty-io:9.2.12.v20150709
and
+-com.ztbsuper:dingding-notifications:1.11-SNAPSHOT
  +-org.jenkins-ci.main:jenkins-test-harness:2.13
    +-org.eclipse.jetty:jetty-security:9.2.15.v20160210
      +-org.eclipse.jetty:jetty-server:9.2.15.v20160210
        +-org.eclipse.jetty:jetty-io:9.2.12.v20150709 (managed) <-- org.eclipse.jetty:jetty-io:9.2.15.v20160210
and
+-com.ztbsuper:dingding-notifications:1.11-SNAPSHOT
  +-org.jenkins-ci.main:jenkins-test-harness:2.13
    +-org.jenkins-ci.main:jenkins-test-harness-htmlunit:2.18-1
      +-org.eclipse.jetty.websocket:websocket-client:9.2.12.v20150709
        +-org.eclipse.jetty:jetty-io:9.2.12.v20150709 (managed) <-- org.eclipse.jetty:jetty-io:9.2.15.v20160210
and
+-com.ztbsuper:dingding-notifications:1.11-SNAPSHOT
  +-org.jenkins-ci.main:jenkins-test-harness:2.13
    +-org.jenkins-ci.main:jenkins-test-harness-htmlunit:2.18-1
      +-org.eclipse.jetty.websocket:websocket-common:9.2.12.v20150709
        +-org.eclipse.jetty:jetty-io:9.2.12.v20150709 (managed) <-- org.eclipse.jetty:jetty-io:9.2.15.v20160210
, 

发现还有 jetty-io  的错误提示,不要慌,仔细看,错误提示不一样了,

+-org.eclipse.jetty:jetty-io:9.2.12.v20150709 (managed) <-- org.eclipse.jetty:jetty-io:9.2.15.v20160210
这里提示,jetty-io 版本使用 9.2.15.v20160210 版本

    
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.apache.antgroupId>
                <artifactId>antartifactId>
                <version>1.9.2version>
            dependency>
            <dependency>
                <groupId>org.eclipse.jettygroupId>
                <artifactId>jetty-utilartifactId>
                <version>9.2.15.v20160210version>
            dependency>
            <dependency>
                <groupId>org.eclipse.jettygroupId>
                <artifactId>jetty-ioartifactId>
                <version>9.2.15.v20160210version>
            dependency>
            <dependency>
                <groupId>org.codehaus.plexusgroupId>
                <artifactId>plexus-utilsartifactId>
                <version>2.1version>
            dependency>
        dependencies>
    dependencyManagement>

再次compile就不会有  jetty-io   jar包冲突了

 


推荐阅读
author-avatar
秋静222
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有