From 113d8114227f56100cfc9eff1d4f2f8ed1ec9185 Mon Sep 17 00:00:00 2001 From: Martin Chalupa Date: Fri, 21 Aug 2020 15:01:40 -0700 Subject: [PATCH] Core platform applied through recommender plugin (when using feature flag) are not propagated into consumable apiElements and runtimeElements. It means they are not published as dependendencies --- .../ExtendRecommenderConfigurationAction.java | 7 ++- ...nsPluginCompositeCoreBomSupportSpec.groovy | 4 +- ...mmendationsPluginCoreBomSupportSpec.groovy | 49 +++++++++++++++++++ 3 files changed, 57 insertions(+), 3 deletions(-) diff --git a/src/main/groovy/netflix/nebula/dependency/recommender/ExtendRecommenderConfigurationAction.java b/src/main/groovy/netflix/nebula/dependency/recommender/ExtendRecommenderConfigurationAction.java index 25fc578..78f50a1 100644 --- a/src/main/groovy/netflix/nebula/dependency/recommender/ExtendRecommenderConfigurationAction.java +++ b/src/main/groovy/netflix/nebula/dependency/recommender/ExtendRecommenderConfigurationAction.java @@ -23,7 +23,7 @@ public ExtendRecommenderConfigurationAction(Configuration bom, Project project, @Override public void execute(Configuration configuration) { - if (container.getExcludedConfigurations().contains(configuration.getName()) || isCopyOfBomConfiguration(configuration)) { + if (!isClasspathConfiguration(configuration) || container.getExcludedConfigurations().contains(configuration.getName()) || isCopyOfBomConfiguration(configuration)) { return; } @@ -41,6 +41,11 @@ public void execute(Configuration configuration) { } } + //we want to apply recommendation only into final resolvable configurations like `compileClasspath` or `runtimeClasspath` across all source sets. + private boolean isClasspathConfiguration(Configuration configuration) { + return configuration.getName().endsWith("Classpath") || configuration.getName().equals("annotationProcessor"); + } + //this action creates clones of bom configuration from root and gradle will also apply the action to them which would //lead to another copy of copy and so on creating infinite loop. We won't apply the action when configuration is copy from bom configuration. private boolean isCopyOfBomConfiguration(Configuration configuration) { diff --git a/src/test/groovy/netflix/nebula/dependency/recommender/DependencyRecommendationsPluginCompositeCoreBomSupportSpec.groovy b/src/test/groovy/netflix/nebula/dependency/recommender/DependencyRecommendationsPluginCompositeCoreBomSupportSpec.groovy index 3dc6bbd..030a4ea 100644 --- a/src/test/groovy/netflix/nebula/dependency/recommender/DependencyRecommendationsPluginCompositeCoreBomSupportSpec.groovy +++ b/src/test/groovy/netflix/nebula/dependency/recommender/DependencyRecommendationsPluginCompositeCoreBomSupportSpec.groovy @@ -117,7 +117,7 @@ class DependencyRecommendationsPluginCompositeCoreBomSupportSpec extends Integra noExceptionThrown() results.standardOutput.contains 'Found project \'project :can-use-recommender-in-a-composite-composite:b\' as substitute for module \'example:b\'.' results.standardOutput.contains '+--- example:b:1.0.0 -> project :can-use-recommender-in-a-composite-composite:b' - results.standardOutput.contains '| +--- project :can-use-recommender-in-a-composite-composite:a' - results.standardOutput.contains '| | +--- test.nebula:foo -> 1.0.0' + results.standardOutput.contains '| \\--- project :can-use-recommender-in-a-composite-composite:a' + results.standardOutput.contains '| \\--- test.nebula:foo -> 1.0.0' } } diff --git a/src/test/groovy/netflix/nebula/dependency/recommender/DependencyRecommendationsPluginCoreBomSupportSpec.groovy b/src/test/groovy/netflix/nebula/dependency/recommender/DependencyRecommendationsPluginCoreBomSupportSpec.groovy index 038f7e7..deaaab8 100644 --- a/src/test/groovy/netflix/nebula/dependency/recommender/DependencyRecommendationsPluginCoreBomSupportSpec.groovy +++ b/src/test/groovy/netflix/nebula/dependency/recommender/DependencyRecommendationsPluginCoreBomSupportSpec.groovy @@ -126,6 +126,55 @@ class DependencyRecommendationsPluginCoreBomSupportSpec extends IntegrationSpec result.standardOutput.contains("+--- test.nebula:app:9.0.0 -> 8.0.0") } + def 'platforms are not published as dependencies of modules'() { + buildFile << """\ + apply plugin: 'nebula.dependency-recommender' + apply plugin: 'maven-publish' + apply plugin: 'java' + apply plugin: 'war' + + repositories { + maven { url '${repo.root.absoluteFile.toURI()}' } + ${generator.mavenRepositoryBlock} + } + + dependencyRecommendations { + mavenBom module: 'test.nebula.bom:testbom:latest.release' + } + + dependencies { + implementation 'test.nebula:moa' + } + + publishing { + publications { + maven(MavenPublication) { + from components.java + versionMapping { + usage('java-api') { + fromResolutionOf('runtimeClasspath') + } + usage('java-runtime') { + fromResolutionResult() + } + } + } + } + } + """.stripIndent() + + when: + runTasksSuccessfully('generateMetadataFileForMavenPublication', 'generatePomFileForMavenPublication') + + then: + def gradleMetadata = new File(projectDir, "build/publications/maven/module.json").text + def pom = new File(projectDir, "build/publications/maven/pom-default.xml").text + ! gradleMetadata.contains('"group": "test.nebula.bom"') + ! gradleMetadata.contains('"module": "testbom"') + ! pom.contains('test.nebula.bom') + ! pom.contains('testbom') + } + @Unroll def 'error when #type(#argType) used'() { given: