Skip to content

Commit

Permalink
Check for ModuleComponentIdentifier explicitly
Browse files Browse the repository at this point in the history
This fixes a future issue with an upcoming Gradle feature
gradle/gradle#30320, where there would be a
new non-module-id resulting in a bug similar to
gradle/gradle#30239.

This also fixes a minor bug as it is technically possible
for getModuleVersion to return null.

See gh-394
  • Loading branch information
octylFractal authored and wilkinsona committed Sep 2, 2024
1 parent e85cd28 commit 09853a2
Showing 1 changed file with 6 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@
import io.spring.gradle.dependencymanagement.internal.pom.Pom;
import io.spring.gradle.dependencymanagement.internal.pom.PomReference;
import io.spring.gradle.dependencymanagement.internal.pom.PomResolver;
import org.gradle.api.artifacts.ModuleVersionIdentifier;
import org.gradle.api.artifacts.component.ProjectComponentIdentifier;
import org.gradle.api.artifacts.component.ModuleComponentIdentifier;
import org.gradle.api.artifacts.result.ResolvedComponentResult;

/**
Expand All @@ -58,17 +57,16 @@ Map<String, Exclusions> resolveExclusions(Collection<ResolvedComponentResult> re
List<PomReference> pomReferences = new ArrayList<>();
Map<String, Exclusions> exclusionsById = new HashMap<>();
for (ResolvedComponentResult resolvedComponent : resolvedComponents) {
ModuleVersionIdentifier moduleVersion = resolvedComponent.getModuleVersion();
if (!(resolvedComponent.getId() instanceof ProjectComponentIdentifier) && moduleVersion.getGroup() != null
&& moduleVersion.getName() != null) {
String id = moduleVersion.getGroup() + ":" + moduleVersion.getName();
if (resolvedComponent.getId() instanceof ModuleComponentIdentifier) {
ModuleComponentIdentifier identifier = (ModuleComponentIdentifier) resolvedComponent.getId();
String id = identifier.getGroup() + ":" + identifier.getModule();
Exclusions exclusions = this.exclusionsCache.get(id);
if (exclusions != null) {
exclusionsById.put(id, exclusions);
}
else {
pomReferences.add(new PomReference(new Coordinates(moduleVersion.getGroup(),
moduleVersion.getName(), moduleVersion.getVersion())));
pomReferences.add(new PomReference(
new Coordinates(identifier.getGroup(), identifier.getModule(), identifier.getVersion())));
}
}
}
Expand Down

0 comments on commit 09853a2

Please sign in to comment.