diff --git a/api/maven-api-core/src/main/java/org/apache/maven/api/plugin/Mojo.java b/api/maven-api-core/src/main/java/org/apache/maven/api/plugin/Mojo.java
index ca90438dd348..277d4ba6ffe1 100644
--- a/api/maven-api-core/src/main/java/org/apache/maven/api/plugin/Mojo.java
+++ b/api/maven-api-core/src/main/java/org/apache/maven/api/plugin/Mojo.java
@@ -23,9 +23,28 @@
import org.apache.maven.api.annotations.ThreadSafe;
/**
- * This interface forms the contract required for Mojos to interact with the Maven infrastructure.
- * It features an {@link #execute()} method, which triggers the Mojo's build-process behavior,
- * and can throw a {@link MojoException} if error conditions occur.
+ * Represents the contract for Mojos to interact with the Maven infrastructure.
+ * Implementations of this interface define specific build-process behaviors
+ * that are triggered during a Maven build lifecycle.
+ *
+ * The primary entry point is the {@link #execute()} method, which encapsulates
+ * the behavior of the Mojo and serves as the integration point with Maven. This
+ * method may throw an {@link Exception} to signal any issues that prevent
+ * successful execution of the Mojo.
+ *
+ *
+ * Annotations:
+ *
+ *
+ * - {@link Experimental}: Indicates that this interface or its implementation
+ * may still be evolving and could change in future versions.
+ * - {@link FunctionalInterface}: Denotes that this is a functional interface,
+ * allowing implementations as lambda expressions or method references.
+ * - {@link Consumer}: Signifies that this type is intended to be implemented
+ * or extended by Maven plugins or extensions and consumed by Maven itself.
+ * - {@link ThreadSafe}: Implies that implementations of this interface must
+ * be safe to invoke from multiple threads concurrently.
+ *
*
* @since 4.0.0
*/
@@ -35,11 +54,15 @@
@ThreadSafe
public interface Mojo {
/**
- * Perform whatever build-process behavior this {@code Mojo} implements.
- * This is the main trigger for the {@code Mojo} inside the Maven system,
- * and allows the {@code Mojo} to communicate errors.
+ * Executes the behavior defined by this {@code Mojo}. This method is invoked
+ * during the Maven build lifecycle to perform the Mojo's designated task.
+ *
+ * Implementations should handle any task-specific logic and may communicate
+ * errors by throwing an {@link Exception}. Error conditions should provide
+ * sufficient detail to aid troubleshooting.
*
- * @throws MojoException if a problem occurs
+ * @throws Exception if any issue occurs that prevents the successful execution
+ * of the Mojo
*/
- void execute();
+ void execute() throws Exception;
}
diff --git a/impl/maven-core/src/main/java/org/apache/maven/plugin/DefaultBuildPluginManager.java b/impl/maven-core/src/main/java/org/apache/maven/plugin/DefaultBuildPluginManager.java
index 7d3e8c4a7ac2..6d9c76100d8e 100644
--- a/impl/maven-core/src/main/java/org/apache/maven/plugin/DefaultBuildPluginManager.java
+++ b/impl/maven-core/src/main/java/org/apache/maven/plugin/DefaultBuildPluginManager.java
@@ -81,6 +81,7 @@ public DefaultBuildPluginManager(
* @throws PluginResolutionException The plugin could be found but could not be resolved.
* @throws InvalidPluginDescriptorException
*/
+ @Override
public PluginDescriptor loadPlugin(
Plugin plugin, List repositories, RepositorySystemSession session)
throws PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException,
@@ -92,6 +93,7 @@ public PluginDescriptor loadPlugin(
// Mojo execution
// ----------------------------------------------------------------------
+ @Override
public void executeMojo(MavenSession session, MojoExecution mojoExecution)
throws MojoFailureException, MojoExecutionException, PluginConfigurationException, PluginManagerException {
MavenProject project = session.getCurrentProject();
@@ -201,6 +203,7 @@ public void executeMojo(MavenSession session, MojoExecution mojoExecution)
* call, which is not nice.
* @throws PluginResolutionException
*/
+ @Override
public ClassRealm getPluginRealm(MavenSession session, PluginDescriptor pluginDescriptor)
throws PluginResolutionException, PluginManagerException {
ClassRealm pluginRealm = pluginDescriptor.getClassRealm();
@@ -213,6 +216,7 @@ public ClassRealm getPluginRealm(MavenSession session, PluginDescriptor pluginDe
return pluginDescriptor.getClassRealm();
}
+ @Override
public MojoDescriptor getMojoDescriptor(
Plugin plugin, String goal, List repositories, RepositorySystemSession session)
throws PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException,
@@ -228,8 +232,14 @@ private static class MojoWrapper implements Mojo {
}
@Override
- public void execute() {
- mojoV4.execute();
+ public void execute() throws MojoExecutionException {
+ try {
+ mojoV4.execute();
+ } catch (RuntimeException e) {
+ throw e;
+ } catch (Exception e) {
+ throw new MojoExecutionException(e);
+ }
}
@Override