maven 多个父依赖中jar包冲突解决办法
在jenkins插件开发的过程中,maven父项目基本是plugin
在红箭头标记的地方,这两个地方是指定了父项目中一些依赖的版本,但是这两个依赖版本中,各自依赖的一些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包为例。
可以看到 这个jar包在项目里有两个版本号,是在 jenkins-test-harness 里,这个就是我们引入的plugin 父模块中的,此时exclude也不好使,那么办法是使用 dependencyManagement 这个标签来锁定一些jar包的版本,部分配置如下:
<!-- 锁定版本,ant 1.9.2 --> <dependencyManagement> <dependencies> <dependency> <groupId>org.apache.ant</groupId> <artifactId>ant</artifactId> <version>1.9.2</version> </dependency> <dependency> <groupId>org.eclipse.jetty</groupId> <artifactId>jetty-util</artifactId> <version>9.2.15.v20160210</version> </dependency> <dependency> <groupId>org.eclipse.jetty</groupId> <artifactId>jetty-io</artifactId> <version>9.2.12.v20150709</version> </dependency> <dependency> <groupId>org.codehaus.plexus</groupId> <artifactId>plexus-utils</artifactId> <version>2.1</version> </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 版本
<!-- 锁定版本,ant 1.9.2 --> <dependencyManagement> <dependencies> <dependency> <groupId>org.apache.ant</groupId> <artifactId>ant</artifactId> <version>1.9.2</version> </dependency> <dependency> <groupId>org.eclipse.jetty</groupId> <artifactId>jetty-util</artifactId> <version>9.2.15.v20160210</version> </dependency> <dependency> <groupId>org.eclipse.jetty</groupId> <artifactId>jetty-io</artifactId> <version>9.2.15.v20160210</version> </dependency> <dependency> <groupId>org.codehaus.plexus</groupId> <artifactId>plexus-utils</artifactId> <version>2.1</version> </dependency> </dependencies> </dependencyManagement>
再次compile就不会有 jetty-io jar包冲突了
本文来自博客园,作者:margo,转载请注明原文链接:https://www.cnblogs.com/ZMargo/articles/11806042.html