Skip to content

Commit

Permalink
Fix MergePlugin transitive dependencies
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Rob Winch committed Aug 31, 2016
1 parent 634d1c0 commit 09f1674
Showing 1 changed file with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class MergePlugin implements Plugin<Project> {
project.plugins.apply(IdeaPlugin)

MergeModel model = project.extensions.create("merge", MergeModel)
model.project = project
project.configurations.create("merging")
Configuration runtimeMerge = project.configurations.create("runtimeMerge")

Expand All @@ -76,6 +77,7 @@ class MergePlugin implements Plugin<Project> {
if (it.merge.into != null) {
setup(it)
}
setupIdeDependencies(it)
}

// Hook to build runtimeMerge dependencies
Expand Down Expand Up @@ -114,6 +116,16 @@ class MergePlugin implements Plugin<Project> {
}
}

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])
Expand Down Expand Up @@ -154,5 +166,12 @@ class MergePlugin implements Plugin<Project> {
}

class MergeModel {
Project project;
Project into;
List<Project> from = [];

public void setInto(Project into) {
this.into = into;
into.merge.from.add(project);
}
}

0 comments on commit 09f1674

Please sign in to comment.