Skip to content

Commit

Permalink
Merge pull request gradle#27006 Deduplicate dependency management ent…
Browse files Browse the repository at this point in the history
…ries in POMs

Fix a regression where previously we would check that we did not add duplicate entries to the dependency-management section of the POM. We still properly de-duplicate regular dependencies.
Fixes: gradle#26996

Before merging the PR, comments starting with
- ❌ ❓**must** be fixed
- 🤔 💅 **should** be fixed
- 💭 **may** be fixed
- 🎉 celebrate happy things

Co-authored-by: Justin Van Dort <[email protected]>
  • Loading branch information
bot-gradle and jvandort committed Nov 9, 2023
2 parents f1c5e86 + e216a1e commit b5adc02
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,62 @@ class MavenPublishDependenciesIntegTest extends AbstractMavenPublishIntegTest {
}
}

@Issue("https://github.com/gradle/gradle/issues/26996")
def "BOMs are not published multiple times"() {
given:
mavenRepo.module("org", "foo").publish()
settingsFile << "rootProject.name = 'root'"
buildFile << """
plugins {
id("java-library")
id("maven-publish")
}
group = 'group'
version = '1.0'
repositories { maven { url "${mavenRepo.uri}" } }
dependencies {
api platform("org:foo:1.0")
}
publishing {
repositories {
maven { url "${mavenRepo.uri}" }
}
publications {
maven(MavenPublication) {
from components.java
}
}
}
"""

when:
succeeds "publish"

then:
repoModule.assertPublished()
def depMan = (repoModule.parsedPom.dependencyManagement.get("dependencies"))[0] as Node
depMan.children().size() == 1
with(depMan.children().first()) {
groupId.text() == "org"
artifactId.text() == "foo"
version.text() == "1.0"
type.text() == "pom"
scope.text() == "import"
}

["apiElements", "runtimeElements"].each {
repoModule.parsedModuleMetadata.variant(it) {
dependency("org:foo:1.0") {
exists()
isLast()
}
}
}
}

def "dependencies with multiple dependency artifacts are mapped to multiple dependency declarations in GMM"() {
given:
settingsFile << "rootProject.name = 'root'"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ public ParsedDependencyResult parseDependencies(
LOG, UNSUPPORTED_FEATURE, INCOMPATIBLE_FEATURE, PUBLICATION_WARNING_FOOTER, "suppressPomMetadataWarningsFor");

Set<MavenDependencyKey> seenDependencies = Sets.newHashSet();
Set<MavenDependencyKey> seenPlatforms = Sets.newHashSet();
Set<DependencyConstraint> seenConstraints = Sets.newHashSet();

List<MavenDependency> dependencies = new ArrayList<>();
Expand Down Expand Up @@ -170,14 +171,19 @@ public ParsedDependencyResult parseDependencies(
dependencies.add(dep);
}
};
Consumer<MavenDependency> platformsAdder = dep -> {
if (seenPlatforms.add(MavenDependencyKey.of(dep))) {
platforms.add(dep);
}
};

for (ModuleDependency dependency : variant.getDependencies()) {
if (isDependencyWithDefaultArtifact(dependency) && dependencyMatchesProject(dependency, coordinates)) {
// We skip all self referencing dependency declarations, unless they have custom artifact information
continue;
}
if (platformSupport.isTargetingPlatform(dependency)) {
dependencyFactory.convertImportDependencyConstraint(dependency, platforms::add);
dependencyFactory.convertImportDependencyConstraint(dependency, platformsAdder);
} else {
dependencyFactory.convertDependency(dependency, dependencyAdder);
}
Expand Down

0 comments on commit b5adc02

Please sign in to comment.