2

I have a custom Maven plugin that I'm trying to bind to the package phase by default. I've tried every combination of using the @Mojo annotation along with the @Execute annotation, but it doesn't seem to auto bind.

The only way I manage to get my plugin to work is by defining it like this:

@Mojo(name = "put")
public class SSHMojo extends AbstractMojo {

And then in my project using the plugin, defining an execution. I'd like to avoid having to add the <executions> every time I want to use my plugin.

<plugin>
  <groupId>com.patrickgrimard</groupId>
  <artifactId>ssh-maven-plugin</artifactId>
  <version>1.0.2</version>
  <executions>
    <execution>
      <phase>package</phase>
      <goals>
        <goal>put</goal>
      </goals>
    </execution>
  </executions>
  <configuration>
    <serverId>devopsmtl</serverId>
    <host>example.com</host>
    <remoteDirectory>/srv/www</remoteDirectory>
  </configuration>
</plugin>

My full plugin pom can be found at https://github.com/pgrimard/ssh-maven-plugin/blob/master/pom.xml

Patrick Grimard
  • 7,033
  • 8
  • 51
  • 68

2 Answers2

3

Hi simply use the following:

@Mojo( name = "put", defaultPhase = LifecyclePhase.PACKAGE )

Apart from that i would suggest to use a newer version of maven-plugin-api (3.0 at least)...

khmarbaise
  • 92,914
  • 28
  • 189
  • 235
  • 1
    I've upgraded the maven-plugin-api to 3.3.3 and added the defaultPhase, but it still doesn't run my plugin unless I specify the execution in my pom. – Patrick Grimard Aug 12 '15 at 16:47
  • Show the example pom which you are using for it...Apart from that you know [wagon-maven-plugin](http://www.mojohaus.org/wagon-maven-plugin/) – khmarbaise Aug 13 '15 at 07:15
2
  1. Use annotation attribute defaultPhase (like already mentioned by khmarbaise):
@Mojo(name = "put", defaultPhase = LifecyclePhase.PACKAGE)
public class SSHMojo extends AbstractMojo { ... }


  1. In the pom.xml of the consuming Maven project you can leave away the reference to the phase after this:
<plugin>
  <groupId>com.patrickgrimard</groupId>
  <artifactId>ssh-maven-plugin</artifactId>
  <version>1.0.2</version>
  <executions>
    <execution>
      <!-- <phase>package</phase> --><!-- needed no longer -->
      <goals>
        <goal>put</goal>
      </goals>
    </execution>
  </executions>
  ...
user1364368
  • 1,474
  • 1
  • 16
  • 22