gnodet commented on code in PR #1690:
URL: https://github.com/apache/maven/pull/1690#discussion_r1738039329


##########
maven-core/src/main/java/org/apache/maven/project/ReactorModelPool.java:
##########
@@ -48,13 +49,20 @@ class ReactorModelPool {
      * @throws IllegalStateException if version was null and multiple modules 
share the same groupId + artifactId
      */
     public Model get(String groupId, String artifactId, String version) {
-        return modelsByGa.getOrDefault(new GAKey(groupId, artifactId), 
Collections.emptySet()).stream()
-                .filter(m -> version == null || version.equals(getVersion(m)))
-                .reduce((a, b) -> {
-                    throw new IllegalStateException(
-                            "Multiple modules with key " + a.getGroupId() + 
':' + a.getArtifactId());
-                })
-                .orElse(null);
+        Collection<Model> models = modelsByGa.getOrDefault(new GAKey(groupId, 
artifactId), Collections.emptySet());
+        if (models.isEmpty()) {
+            return null;
+        } else if (models.size() == 1) {
+            return models.iterator().next();
+        } else {
+            return models.stream()
+                    .filter(m -> version == null || 
version.equals(getVersion(m)))
+                    .reduce((a, b) -> {
+                        throw new IllegalStateException(
+                                "Multiple modules with key " + a.getGroupId() 
+ ':' + a.getArtifactId());
+                    })
+                    .orElse(null);
+        }

Review Comment:
   Oh, it does change the behaviour, as if there's a single version, it will 
always be used, even if there's a version mismatch.  I think that's wrong.
   Multiple versions of the same GA inside a reactor is a supported (albeit 
rare) use case.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@maven.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to