@@ -326,7 +326,7 @@ private static void executeMojo(MavenSession session, MojoExecution execution, I
326326 artifacts .put (project , new LinkedHashSet <>(project .getArtifacts ()));
327327 snapshots .put (project , MavenProjectMutableState .takeSnapshot (project ));
328328 }
329- MojoExecution clone = new MojoExecution (execution . getPlugin (), execution . getGoal (), execution . getExecutionId () );
329+ MojoExecution clone = cloneMojoExecution (execution );
330330 try {
331331 MavenProject currentProject = session .getCurrentProject ();
332332 LifecycleExecutionPlanCalculator executionPlanCalculator = lookup .lookup (LifecycleExecutionPlanCalculator .class );
@@ -351,6 +351,26 @@ private static void executeMojo(MavenSession session, MojoExecution execution, I
351351 }
352352 }
353353
354+ private static MojoExecution cloneMojoExecution (MojoExecution execution ) {
355+ MojoExecution clone = new MojoExecution (execution .getPlugin (), execution .getGoal (), execution .getExecutionId ());
356+ //FIXME something's wrong with this "cloning" approach, as we lose the original mojoDescriptor.
357+ // Intuitively, something like the following looks more "right", as it would clone the mojoDescriptor,
358+ // in order to avoid any caching shenanigans as mentioned in https://github.com/eclipse-m2e/m2e-core/issues/1304#issuecomment-1457955512.
359+ // but even cloning the descriptor leads to an occurrence of https://github.com/eclipse-m2e/m2e-core/issues/1150 on project import
360+ // var descriptor = execution.getMojoDescriptor();
361+ // if(descriptor != null) {
362+ // clone = new MojoExecution(execution.getPlugin(), execution.getGoal(), execution.getExecutionId());
363+ // } else {
364+ // clone = new MojoExecution(descriptor.clone(), execution.getExecutionId(), execution.getSource());
365+ // }
366+ clone .setConfiguration (execution .getConfiguration ());
367+ clone .setLifecyclePhase (execution .getLifecyclePhase ());
368+ execution .getForkedExecutions ().forEach ((k , v ) -> {
369+ clone .setForkedExecutions (k , v );
370+ });
371+ return clone ;
372+ }
373+
354374 private <V > V executeBare (MavenProject project , ICallable <V > callable , IProgressMonitor monitor )
355375 throws CoreException {
356376 final MavenSession mavenSession = getSession ();
0 commit comments