Recursively add test dependencies

Update TestSourceSetDependenciesPlugin to recursively search project
dependencies when adding test source sets.
This commit is contained in:
Phillip Webb 2013-01-02 11:51:10 -08:00
parent c892b81852
commit 0b2c305072
1 changed files with 15 additions and 9 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2013 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.
@ -34,18 +34,24 @@ class TestSourceSetDependenciesPlugin implements Plugin<Project> {
public void apply(Project project) {
project.afterEvaluate {
Set<ProjectDependency> projectDependencies = new LinkedHashSet<>()
for(def configurationName in ["compile", "optional", "provided"]) {
Configuration configuration = project.getConfigurations().findByName(configurationName)
if(configuration) {
projectDependencies.addAll(
configuration.dependencies.findAll { it instanceof ProjectDependency }
)
}
}
collectProjectDependencies(projectDependencies, project)
projectDependencies.each {
project.dependencies.add("testCompile", it.dependencyProject.sourceSets.test.output)
}
}
}
private void collectProjectDependencies(Set<ProjectDependency> projectDependencies,
Project project) {
for(def configurationName in ["compile", "optional", "provided"]) {
Configuration configuration = project.getConfigurations().findByName(configurationName)
if(configuration) {
configuration.dependencies.findAll { it instanceof ProjectDependency }.each {
projectDependencies.add(it)
collectProjectDependencies(projectDependencies, it.dependencyProject)
}
}
}
}
}