From 09f16747b582faf12598c63e929a0e8a48be4317 Mon Sep 17 00:00:00 2001 From: Rob Winch Date: Wed, 31 Aug 2016 10:00:36 -0500 Subject: [PATCH] Fix MergePlugin transitive dependencies A little terminiology first: * merge.from - a project that contains source that will be merged into merge.into * merge.into - a project that contains source code that will have code from merge.from merged into it. Previously a module that dependended on merge.into would not see the merge.from module as a transitive dependency. This worked fine from a Gradle build because all the code from merge.from is merged into the merge.into jar. However, in an IDE it did not work because the IDE does not assemble a jar. This fix ensures that merge.from modules are automatically added to the classpath of any module relying on the merge.into project. Fixes SPR-14650 --- .../build/gradle/MergePlugin.groovy | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) 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 44d270adb4..9c9e2f6be2 100644 --- a/buildSrc/src/main/groovy/org/springframework/build/gradle/MergePlugin.groovy +++ b/buildSrc/src/main/groovy/org/springframework/build/gradle/MergePlugin.groovy @@ -64,6 +64,7 @@ class MergePlugin implements Plugin { project.plugins.apply(IdeaPlugin) MergeModel model = project.extensions.create("merge", MergeModel) + model.project = project project.configurations.create("merging") Configuration runtimeMerge = project.configurations.create("runtimeMerge") @@ -76,6 +77,7 @@ class MergePlugin implements Plugin { if (it.merge.into != null) { setup(it) } + setupIdeDependencies(it) } // Hook to build runtimeMerge dependencies @@ -114,6 +116,16 @@ class MergePlugin implements Plugin { } } + private void setupIdeDependencies(Project project) { + project.configurations.each { c -> + c.dependencies.findAll( { it instanceof org.gradle.api.artifacts.ProjectDependency } ).each { d -> + d.dependencyProject.merge.from.each { from -> + project.dependencies.add("runtimeMerge", from) + } + } + } + } + private void setupMaven(Project project) { project.configurations.each { configuration -> Conf2ScopeMapping mapping = project.conf2ScopeMappings.getMapping([configuration]) @@ -154,5 +166,12 @@ class MergePlugin implements Plugin { } class MergeModel { + Project project; Project into; + List from = []; + + public void setInto(Project into) { + this.into = into; + into.merge.from.add(project); + } }