Skip to content

Commit 666a53b

Browse files
author
Christoph Läubrich
committed
MNG-8541 - Support throwing Exception from Mojo#execute
1 parent 63e6881 commit 666a53b

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

api/maven-api-core/src/main/java/org/apache/maven/api/plugin/Mojo.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,12 @@
3535
@ThreadSafe
3636
public interface Mojo {
3737
/**
38-
* Perform whatever build-process behavior this {@code Mojo} implements.
39-
* This is the main trigger for the {@code Mojo} inside the Maven system,
40-
* and allows the {@code Mojo} to communicate errors.
38+
* Perform whatever build-process behavior this {@code Mojo} implements. This is
39+
* the main trigger for the {@code Mojo} inside the Maven system, and allows the
40+
* {@code Mojo} to communicate errors.
4141
*
42-
* @throws MojoException if a problem occurs
42+
* @throws Exception if any problem occurs that prevents the mojo from its
43+
* execution
4344
*/
44-
void execute();
45+
void execute() throws Exception;
4546
}

impl/maven-core/src/main/java/org/apache/maven/plugin/DefaultBuildPluginManager.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ public DefaultBuildPluginManager(
8181
* @throws PluginResolutionException The plugin could be found but could not be resolved.
8282
* @throws InvalidPluginDescriptorException
8383
*/
84+
@Override
8485
public PluginDescriptor loadPlugin(
8586
Plugin plugin, List<RemoteRepository> repositories, RepositorySystemSession session)
8687
throws PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException,
@@ -92,6 +93,7 @@ public PluginDescriptor loadPlugin(
9293
// Mojo execution
9394
// ----------------------------------------------------------------------
9495

96+
@Override
9597
public void executeMojo(MavenSession session, MojoExecution mojoExecution)
9698
throws MojoFailureException, MojoExecutionException, PluginConfigurationException, PluginManagerException {
9799
MavenProject project = session.getCurrentProject();
@@ -201,6 +203,7 @@ public void executeMojo(MavenSession session, MojoExecution mojoExecution)
201203
* call, which is not nice.
202204
* @throws PluginResolutionException
203205
*/
206+
@Override
204207
public ClassRealm getPluginRealm(MavenSession session, PluginDescriptor pluginDescriptor)
205208
throws PluginResolutionException, PluginManagerException {
206209
ClassRealm pluginRealm = pluginDescriptor.getClassRealm();
@@ -213,6 +216,7 @@ public ClassRealm getPluginRealm(MavenSession session, PluginDescriptor pluginDe
213216
return pluginDescriptor.getClassRealm();
214217
}
215218

219+
@Override
216220
public MojoDescriptor getMojoDescriptor(
217221
Plugin plugin, String goal, List<RemoteRepository> repositories, RepositorySystemSession session)
218222
throws PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException,
@@ -228,8 +232,14 @@ private static class MojoWrapper implements Mojo {
228232
}
229233

230234
@Override
231-
public void execute() {
232-
mojoV4.execute();
235+
public void execute() throws org.apache.maven.plugin.MojoExecutionException {
236+
try {
237+
mojoV4.execute();
238+
} catch (RuntimeException e) {
239+
throw e;
240+
} catch (Exception e) {
241+
throw new MojoExecutionException(e);
242+
}
233243
}
234244

235245
@Override

0 commit comments

Comments
 (0)