[
https://issues.apache.org/jira/browse/MNG-8659?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17940906#comment-17940906
]
Niels Basjes commented on MNG-8659:
-----------------------------------
Let me elaborate a bit about my specific usecase and how I see it right now.
I have a plugin that generates both source code (i.e. 'main') and test code
(i.e. 'test') from an input (Yaml in my case).
This requires the input to be specified and things like language (Java/Kotlin),
a package name and a class name for the code that is to be generated.
These are 2 Mojos each attached to a different phase (generate-sources and
generate-test-sources) and use the exact same configuration as input because
the code and tests must use the same package names and class names to work
correctly.
If I have 1 input to process I now have to configure (simplified the format to
make it easier to explain)
{code:java}
plugin
configuration
input=foo.yaml
executions
execution
generate-main
execution
generate-test{code}
or
{code:java}
plugin
executions
execution
configuration
input=foo.yaml
generate-main
execution
configuration
input=foo.yaml
generate-test{code}
My proposal of Mojos that run implicitly as defined in the plugin would
simplify this to
{code:java}
plugin
configuration
input=foo.yaml{code}
Something I am wondering about is how the case of wanting 2 input-output
combinations in a single project.
Currently that will blow up to this where all configurations must be present
twice making it error prone.
{code:java}
plugin
executions
execution
configuration
input=foo.yaml
generate-main
execution
configuration
input=foo.yaml
generate-test
execution
configuration
input=bar.yaml
generate-main
execution
configuration
input=bar.yaml
generate-test{code}
One possible way to handle this in combination with the automatic running of
the default mojos could be this:
{code:java}
plugin
configurations <--- Note the extra level here which can only be used with
these automatically executing Mojos.
configuration
input=foo.yaml
configuration
input=bar.yaml {code}
> Allow maven plugins to automatically run a Mojo without an explicit execution.
> ------------------------------------------------------------------------------
>
> Key: MNG-8659
> URL: https://issues.apache.org/jira/browse/MNG-8659
> Project: Maven
> Issue Type: Improvement
> Components: Plugin API
> Reporter: Niels Basjes
> Priority: Major
>
> 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.
> {code:java}
> <plugin>
> <groupId>nl.basjes.maven</groupId>
> <artifactId>my-special-maven-plugin</artifactId>
> <version>1.0.0</version>
> <configuration>
> <something>foo</something>
> <somemore>bar</somemore>
> </configuration>
> </plugin> {code}
> 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:
> {quote}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!
> {quote}
> Then an author can do something like this:
> {code:java}
> @Mojo(name = "generate-main", defaultPhase = LifecyclePhase.GENERATE_SOURCES,
> threadSafe = true, autoExecution = true) {code}
>
> 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
--
This message was sent by Atlassian Jira
(v8.20.10#820010)