4040import java .util .Set ;
4141import java .util .concurrent .Callable ;
4242import java .util .concurrent .ConcurrentHashMap ;
43+ import java .util .concurrent .CopyOnWriteArrayList ;
4344import java .util .concurrent .Executor ;
4445import java .util .concurrent .Executors ;
4546import java .util .concurrent .atomic .AtomicReference ;
7374import org .apache .maven .api .model .Repository ;
7475import org .apache .maven .api .services .BuilderProblem ;
7576import org .apache .maven .api .services .BuilderProblem .Severity ;
77+ import org .apache .maven .api .services .MavenException ;
7678import org .apache .maven .api .services .ModelBuilder ;
7779import org .apache .maven .api .services .ModelBuilderException ;
7880import org .apache .maven .api .services .ModelBuilderRequest ;
@@ -739,6 +741,7 @@ private void buildBuildPom() throws ModelBuilderException {
739741 // For the top model and all its children, build the effective model.
740742 // This is done through the phased executor
741743 var allResults = results (result ).toList ();
744+ List <RuntimeException > exceptions = new CopyOnWriteArrayList <>();
742745 try (PhasingExecutor executor = createExecutor ()) {
743746 for (DefaultModelBuilderResult r : allResults ) {
744747 executor .execute (() -> {
@@ -747,15 +750,21 @@ private void buildBuildPom() throws ModelBuilderException {
747750 mbs .buildEffectiveModel (new LinkedHashSet <>());
748751 } catch (ModelBuilderException e ) {
749752 // gathered with problem collector
750- } catch (Exception t ) {
751- mbs .add (Severity . FATAL , ModelProblem . Version . BASE , t . getMessage (), t );
753+ } catch (RuntimeException t ) {
754+ exceptions .add (t );
752755 }
753756 });
754757 }
755758 }
756759
757760 // Check for errors again after execution
758- if (hasErrors ()) {
761+ if (exceptions .size () == 1 ) {
762+ throw exceptions .get (0 );
763+ } else if (exceptions .size () > 1 ) {
764+ MavenException fatalException = new MavenException ("Multiple fatal exceptions occurred" );
765+ exceptions .forEach (fatalException ::addSuppressed );
766+ throw fatalException ;
767+ } else if (hasErrors ()) {
759768 throw newModelBuilderException ();
760769 }
761770 }
0 commit comments