在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包沖突了
