diff --git a/src/main/java/org/apache/maven/plugins/invoker/AbstractInvokerMojo.java b/src/main/java/org/apache/maven/plugins/invoker/AbstractInvokerMojo.java index 5644fe2a..2b06cf6d 100644 --- a/src/main/java/org/apache/maven/plugins/invoker/AbstractInvokerMojo.java +++ b/src/main/java/org/apache/maven/plugins/invoker/AbstractInvokerMojo.java @@ -695,6 +695,18 @@ public abstract class AbstractInvokerMojo extends AbstractMojo { @Parameter(defaultValue = "false", property = "invoker.updateSnapshots") private boolean updateSnapshots; + /** + * Projects that are cloned undergo some filtering. In order to grab all projects and make sure + * they are all filtered, projects are read and parsed. In some cases, this may not be a desired + * behavior (especially when some pom.xml cannot be parsed by Maven directly). In such cases, + * the exact list of projects can be set using this field, avoiding the parsing of all pom.xml + * files found. + * + * @since 3.9.0 + */ + @Parameter + private List collectedProjects; + // internal state variables /** @@ -802,11 +814,6 @@ public void execute() throws MojoExecutionException, MojoFailureException { handleScriptRunnerWithScriptClassPath(); - Collection collectedProjects = new LinkedHashSet<>(); - for (BuildJob buildJob : buildJobs) { - collectProjects(projectsDirectory, buildJob.getProject(), collectedProjects, true); - } - File projectsDir = projectsDirectory; if (cloneProjectsTo == null && "maven-plugin".equals(project.getPackaging())) { @@ -826,6 +833,13 @@ public void execute() throws MojoExecutionException, MojoFailureException { } if (cloneProjectsTo != null) { + Collection collectedProjects = this.collectedProjects; + if (collectedProjects == null) { + collectedProjects = new LinkedHashSet<>(); + for (BuildJob buildJob : buildJobs) { + collectProjects(projectsDirectory, buildJob.getProject(), collectedProjects, true); + } + } cloneProjects(collectedProjects); addMissingDotMvnDirectory(cloneProjectsTo, buildJobs); projectsDir = cloneProjectsTo; @@ -1088,7 +1102,7 @@ private boolean isNotEmpty(String s) { * * @param projectPaths The paths to the projects to clone, relative to the projects directory, must not be * null nor contain null elements. - * @throws org.apache.maven.plugin.MojoExecutionException If the the projects could not be copied/filtered. + * @throws org.apache.maven.plugin.MojoExecutionException If the projects could not be copied/filtered. */ private void cloneProjects(Collection projectPaths) throws MojoExecutionException { if (!cloneProjectsTo.mkdirs() && cloneClean) {