You cannot do this easily. Maven plugins do not work, throwing org.apache.maven.plugin.MojoExecutionException or org.apache.maven.plugin.MojoFailureException and you do not have a hook to listen to these exceptions. Of course not with the plugin, because your plugin will not execute after the crash.
It may be possible to use custom versions
org.apache.maven.lifecycle.DefaultLifecycleExecutor or org.apache.maven.DefaultMaven
which you can enter through the plexus and terminate the plugin in try / catch in order to execute your logic later, but this is very heavy stuff.
Read here plexus container access
source share