diff --git a/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java b/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java index 09ab3fe9eb54..1c7c98b88118 100644 --- a/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java +++ b/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java @@ -499,23 +499,30 @@ private List build(File pomFile, boolean recursive) { List results = new ArrayList<>(); List allModels = results(result).toList(); for (ModelBuilderResult r : allModels) { - File pom = r.getSource().getPath().toFile(); - MavenProject project = projectIndex.get(r.getEffectiveModel().getId()); - Path rootDirectory = rootLocator.findRoot(pom.getParentFile().toPath()); - project.setRootDirectory(rootDirectory); - project.setFile(pom); - project.setExecutionRoot(pom.equals(pomFile)); - initProject(project, r); - project.setCollectedProjects(results(r) - .filter(cr -> cr != r) - .map(cr -> projectIndex.get(cr.getEffectiveModel().getId())) - .collect(Collectors.toList())); - - DependencyResolutionResult resolutionResult = null; - if (request.isResolveDependencies()) { - resolutionResult = resolveDependencies(project); + if (r.getEffectiveModel() != null) { + File pom = r.getSource().getPath().toFile(); + MavenProject project = + projectIndex.get(r.getEffectiveModel().getId()); + Path rootDirectory = + rootLocator.findRoot(pom.getParentFile().toPath()); + project.setRootDirectory(rootDirectory); + project.setFile(pom); + project.setExecutionRoot(pom.equals(pomFile)); + initProject(project, r); + project.setCollectedProjects(results(r) + .filter(cr -> cr != r) + .map(cr -> projectIndex.get(cr.getEffectiveModel().getId())) + .collect(Collectors.toList())); + + DependencyResolutionResult resolutionResult = null; + if (request.isResolveDependencies()) { + resolutionResult = resolveDependencies(project); + } + results.add( + new DefaultProjectBuildingResult(project, convert(result.getProblems()), resolutionResult)); + } else { + results.add(new DefaultProjectBuildingResult(null, convert(result.getProblems()), null)); } - results.add(new DefaultProjectBuildingResult(project, convert(result.getProblems()), resolutionResult)); } return results; }