Skip to content

Commit

Permalink
Merge pull request #116 from chali/DontPublishCorePlatformsAsDependen…
Browse files Browse the repository at this point in the history
…cies

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
  • Loading branch information
chali authored Aug 24, 2020
2 parents c855d74 + 113d811 commit 1569d03
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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('<groupId>test.nebula.bom</groupId>')
! pom.contains('<artifactId>testbom</artifactId>')
}

@Unroll
def 'error when #type(#argType) used'() {
given:
Expand Down

0 comments on commit 1569d03

Please sign in to comment.