Skip to content

Commit

Permalink
Make evaluation of dependencies for BOM genration lazy, and occur onl…
Browse files Browse the repository at this point in the history
…y when withXml is called
  • Loading branch information
DanielThomas committed Jul 13, 2016
1 parent 0ac87bc commit 11b9cbe
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class MavenBomXmlGenerator {
else if(Iterable.class.isAssignableFrom(configurationsRet.class))
configurations = configurationsRet

generateDependencyManagementXml(pub, configurations.collect { getManagedDependencies(it) }.flatten())
generateDependencyManagementXml(pub, { configurations.collect { getManagedDependencies(it) }.flatten() })
}

void withDependencies(Closure dependenciesClosure) {
Expand All @@ -38,10 +38,10 @@ class MavenBomXmlGenerator {
else if(Iterable.class.isAssignableFrom(dependenciesRet.class))
dependencies = dependenciesRet

generateDependencyManagementXml(pub, dependencies.collect { ModuleNotationParser.parse(it) })
generateDependencyManagementXml(pub, { dependencies.collect { ModuleNotationParser.parse(it) } })
}

protected static generateDependencyManagementXml(MavenPublication pub, Iterable<ModuleVersionIdentifier> deps) {
protected static generateDependencyManagementXml(MavenPublication pub, Closure<Iterable<ModuleVersionIdentifier>> deps) {
pub.pom.withXml {
Node root = it.asNode()
def dependencyManagement = root.getByName("dependencyManagement")
Expand All @@ -53,7 +53,7 @@ class MavenBomXmlGenerator {
else
dependencies = dependencyManagement[0].getByName("dependencies")[0]

deps.each { mvid ->
deps.call().each { mvid ->
Node dep = dependencies.appendNode("dependency")
dep.appendNode("groupId").value = mvid.group
dep.appendNode("artifactId").value = mvid.name
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package netflix.nebula.dependency.recommender.publisher

import nebula.test.ProjectSpec
import netflix.nebula.dependency.recommender.DependencyRecommendationsPlugin
import org.gradle.api.publish.maven.MavenPublication
import org.gradle.api.publish.maven.plugins.MavenPublishPlugin

class MavenBomXmlGeneratorSpec extends ProjectSpec {
def 'configure a publication with BOM generation'() {
given:
project.plugins.apply(MavenPublishPlugin)
project.plugins.apply(DependencyRecommendationsPlugin)
project.configurations.create('recommendation')

project.publishing {
publications {
recommender(MavenPublication) {
project.nebulaDependencyManagement.fromConfigurations {
project.configurations.recommendation
}
}
}
}

when:
project.publishing

then:
noExceptionThrown()
}
}

0 comments on commit 11b9cbe

Please sign in to comment.