apache / apache/maven

[MNG-8659] Allow maven plugins to automatically run a Mojo without an explicit execution.

Open
#10,433 4 comments 0 reactions 0 assignees View on GitHub
enhancement priority:major
Dominant language
Java
Stars
5.3k
Forks
3.1k
Avg merge
20h 42m
Merged PRs (30d)
297

Description

**[Niels Basjes](https://issues.apache.org/jira/secure/ViewProfile.jspa?name=nielsbasjes)** opened **[MNG-8659](https://issues.apache.org/jira/browse/MNG-8659?redirect=false)** and commented

As discussed here https://the-asf.slack.com/archives/C7Q9JB404/p1743258198334339

Currently an externally developed Maven plugin NEEDS an explicit execution to be specified by the end user. In some cases this explicit execution definition makes things needlessly complex.

The idea is to allow the author of a maven plugin to specify which Mojos are to be run automatically if the plugin is included in a project.

So for example something like this should automatically run a subset of the available Mojos during their assigned defaultPhase.

```java

nl.basjes.maven
my-special-maven-plugin
1.0.0

foo
bar


```

My proposal is to add an extra optional flag (default should be false) to the Mojo annotation that allows the developer to automatically have the Mojo started.

I propose a boolean named   `autoExecution`
With the meaning:

> If set to true then this Mojo will have an implied execution that will run the Mojo during the configured defaultPhase. This requires the defaultPhase to be configured!

Then an author can do something like this:

```java
@Mojo(name = "generate-main", defaultPhase = LifecyclePhase.GENERATE_SOURCES, threadSafe = true, autoExecution = true)
```

 

I think this should use the execution ids already documented as the "implied execution ids" https://maven.apache.org/guides/mini/guide-default-execution-ids.html

---

1 votes, 3 watchers

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.