You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Dirk Olmes <di...@xanthippe.ping.de> on 2019/02/12 08:39:20 UTC

Maven plugin with annotations: default lifecycle phase?

Hi,

I'm creating a Maven plugin using Java Annotations and I'd like my
plugin to be bound to a default lifecycle phase so I don't have to
explicitly bind it to a phase in my regular projects.

So far I use

@Mojo(name = "generate", defaultPhase = LifecyclePhase.GENERATE_SOURCES)
public class MyMojo extends AbstractMojo {}

But that doesn't seem to be enough: just listing the mojo in the build
section of a test project does not execute the plugin.

My google fu fails me! Help!

-dirk

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Maven plugin with annotations: default lifecycle phase?

Posted by Thomas Broyer <t....@gmail.com>.
Adding the plugin won't be enough, you'll have explicitly name the mojo in
an <execution>. What defaultPhase does is that you don't have to specify a
<phase> in the <execution>.
Actually, you can even list all mojos in the same <execution> even if
they're bound to different default phases:
<plugin>
  <groupId>…</groupId>
  <artifactId>…</artifactId>
  <version>…</version>
  <executions>
    <execution>
      <goals>
        <goal>mojo1</goal>
        <goal>mojo2</goal>
        <goal>mojo3</goal>
      </goals>
    </execution>
  </executions>
</plugin>

If you'd want the mojo to be automatically bound without even mentioning
it, you'd have to use a specific lifecycle, i.e. a specific packaging;
you'd then add the plugin with <extensions>true</extensions> and use your
custom <packaging>, and your custom lifecycle would then apply.

On Tue, Feb 12, 2019 at 9:40 AM Dirk Olmes <di...@xanthippe.ping.de> wrote:

> Hi,
>
> I'm creating a Maven plugin using Java Annotations and I'd like my
> plugin to be bound to a default lifecycle phase so I don't have to
> explicitly bind it to a phase in my regular projects.
>
> So far I use
>
> @Mojo(name = "generate", defaultPhase = LifecyclePhase.GENERATE_SOURCES)
> public class MyMojo extends AbstractMojo {}
>
> But that doesn't seem to be enough: just listing the mojo in the build
> section of a test project does not execute the plugin.
>
> My google fu fails me! Help!
>
> -dirk
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>

Re: Maven plugin with annotations: default lifecycle phase?

Posted by Anders Hammar <an...@hammar.net>.
You still need to declare an execution for the plugin in your pom.xml. In
the execution you don't need to declare the phase though as you have a
default one defined in the mojo.

/Anders

On Tue, Feb 12, 2019 at 9:40 AM Dirk Olmes <di...@xanthippe.ping.de> wrote:

> Hi,
>
> I'm creating a Maven plugin using Java Annotations and I'd like my
> plugin to be bound to a default lifecycle phase so I don't have to
> explicitly bind it to a phase in my regular projects.
>
> So far I use
>
> @Mojo(name = "generate", defaultPhase = LifecyclePhase.GENERATE_SOURCES)
> public class MyMojo extends AbstractMojo {}
>
> But that doesn't seem to be enough: just listing the mojo in the build
> section of a test project does not execute the plugin.
>
> My google fu fails me! Help!
>
> -dirk
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>