From 58d8a81b16540cfd7a716373f55ac00e8e9fa39b Mon Sep 17 00:00:00 2001 From: Brian Clozel Date: Mon, 11 May 2015 20:42:24 +0200 Subject: [PATCH] Fix maven dependency scope conflicts in MergePlugin Spring Framework's build is using a custom MergePlugin in order to merge a project into another one and share/override configuration and dependencies. Prior to this commit, two projects merged into a third one could trigger dependency conflicts when exporting the project definition into a POM. When trying to define the scope for a given dependency, those two projects would compete for this with the same priority, resulting in a Gradle exception. One could trigger this issue by running: ./gradlew :spring-orm:install -x javadoc Because `spring-orm-hibernate4` and `spring-orm-hibernate5` get merged into `spring-orm` and both define optional/test dependencies to spring-mvc, etc. This commit makes sure that two projects, when defining dependency scopes, don't use the same priority value; the MergePlugin now adds the index of the current subproject to the priority value. So when two projects compete for this, the one defined in last will define the dependency scope. Issue: SPR-13013 --- .../org/springframework/build/gradle/MergePlugin.groovy | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/buildSrc/src/main/groovy/org/springframework/build/gradle/MergePlugin.groovy b/buildSrc/src/main/groovy/org/springframework/build/gradle/MergePlugin.groovy index fbf683fe81..44d270adb4 100644 --- a/buildSrc/src/main/groovy/org/springframework/build/gradle/MergePlugin.groovy +++ b/buildSrc/src/main/groovy/org/springframework/build/gradle/MergePlugin.groovy @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -132,8 +132,9 @@ class MergePlugin implements Plugin { intoConfiguration.dependencies.add(it) } } + def index = project.parent.childProjects.findIndexOf {p -> p.getValue() == project} project.merge.into.install.repositories.mavenInstaller.pom.scopeMappings.addMapping( - mapping.priority + 100, intoConfiguration, mapping.scope) + mapping.priority + 100 + index, intoConfiguration, mapping.scope) } } }