diff --git a/maven-api-impl/src/main/java/org/apache/maven/internal/impl/model/BuildModelTransformer.java b/maven-api-impl/src/main/java/org/apache/maven/internal/impl/model/BuildModelTransformer.java index ac6bcedbf998..2ac066b2283b 100644 --- a/maven-api-impl/src/main/java/org/apache/maven/internal/impl/model/BuildModelTransformer.java +++ b/maven-api-impl/src/main/java/org/apache/maven/internal/impl/model/BuildModelTransformer.java @@ -90,21 +90,10 @@ void handleCiFriendlyVersion(ModelTransformerContext context, Model model, Path void handleReactorDependencies(ModelTransformerContext context, Model model, Path pomFile, Model.Builder builder) { List newDeps = new ArrayList<>(); boolean modified = false; - String groupId = model.getGroupId(); - InputLocation groupIdLocation = model.getLocation("groupId"); - if (groupId == null) { - groupId = model.getParent().getGroupId(); - groupIdLocation = model.getParent().getLocation("groupId"); - } for (Dependency dep : model.getDependencies()) { Dependency.Builder depBuilder = null; - String depGroupId = dep.getGroupId(); - if (depGroupId == null) { - depGroupId = groupId; - depBuilder = Dependency.newBuilder(dep).groupId(groupId).location("groupId", groupIdLocation); - } if (dep.getVersion() == null) { - Model depModel = context.getRawModel(model.getPomFile(), depGroupId, dep.getArtifactId()); + Model depModel = context.getRawModel(model.getPomFile(), dep.getGroupId(), dep.getArtifactId()); if (depModel != null) { String version = depModel.getVersion(); InputLocation versionLocation = depModel.getLocation("version"); @@ -112,10 +101,17 @@ void handleReactorDependencies(ModelTransformerContext context, Model model, Pat version = depModel.getParent().getVersion(); versionLocation = depModel.getParent().getLocation("version"); } - if (depBuilder == null) { - depBuilder = Dependency.newBuilder(dep); - } + depBuilder = Dependency.newBuilder(dep); depBuilder.version(version).location("version", versionLocation); + if (dep.getGroupId() == null) { + String depGroupId = depModel.getGroupId(); + InputLocation groupIdLocation = depModel.getLocation("groupId"); + if (depGroupId == null && depModel.getParent() != null) { + depGroupId = depModel.getParent().getGroupId(); + groupIdLocation = depModel.getParent().getLocation("groupId"); + } + depBuilder.groupId(depGroupId).location("groupId", groupIdLocation); + } } } if (depBuilder != null) { diff --git a/maven-api-impl/src/main/java/org/apache/maven/internal/impl/model/DefaultModelTransformerContextBuilder.java b/maven-api-impl/src/main/java/org/apache/maven/internal/impl/model/DefaultModelTransformerContextBuilder.java index 08a44afcd14d..76d94a6d3130 100644 --- a/maven-api-impl/src/main/java/org/apache/maven/internal/impl/model/DefaultModelTransformerContextBuilder.java +++ b/maven-api-impl/src/main/java/org/apache/maven/internal/impl/model/DefaultModelTransformerContextBuilder.java @@ -83,7 +83,8 @@ public String getUserProperty(String key) { public Model getRawModel(Path from, String gId, String aId) { Model model = findRawModel(from, gId, aId); if (model != null) { - context.modelByGA.put(new GAKey(gId, aId), new Holder(model)); + String groupId = DefaultModelBuilder.getGroupId(model); + context.modelByGA.put(new GAKey(groupId, model.getArtifactId()), new Holder(model)); context.modelByPath.put(model.getPomFile(), new Holder(model)); } return model; @@ -214,8 +215,18 @@ public ModelTransformerContext build() { } public ModelSource getSource(String groupId, String artifactId) { - Set sources = mappedSources.get(groupId + ":" + artifactId); - if (sources == null) { + Set sources; + if (groupId != null) { + sources = mappedSources.get(groupId + ":" + artifactId); + if (sources == null) { + return null; + } + } else if (artifactId != null) { + sources = mappedSources.get(artifactId); + if (sources == null) { + return null; + } + } else { return null; } return sources.stream() @@ -231,5 +242,6 @@ public void putSource(String groupId, String artifactId, ModelSource source) { mappedSources .computeIfAbsent(groupId + ":" + artifactId, k -> new HashSet<>()) .add(source); + mappedSources.computeIfAbsent(artifactId, k -> new HashSet<>()).add(source); } }