Question

I'm trying to create a plugin which would download and install jars from Maven central as system tools. So I want my line to be like

mvn install-plugin:install org.chaschev:cap4j:1.0

similar to Ruby's

gem install capistrano

This plugin would gather all the needed information about the shortcuts to create from the JAR. I.e. this jar would contain a class implementing an installation interface.

How does Maven understand that in order to execute a command like release:prepare it requires to download the release plugin and to run it? Any better/other way to do this?

Was it helpful?

Solution 2

It is not good to use default Maven groups for your own project. Instead, define your own group for your plugin, like this:

<pluginGroups>
  <pluginGroup>org.chaschev</pluginGroup>
</pluginGroups>

And rename your plugin from cap4j to cap4j-maven-plugin. Then Maven will discover your plugin without further cahnges in POM.

Alternative, without <pluginGroups>, just put following to your POM:

<plugins>
  <plugin>
    <groupId>org.chaschev</groupId>
    <artifactId>cap4j</artifactId>
    <version>...</version>
    <configuration>
      ...
    </configuration>
  </plugin>
  ...
</plugins>

OTHER TIPS

Do you mean how the relation between plugin/goal in the comamnd line and plugin implementation is defined? Then the answer is plugin.xml. See plugin.xml for release plugin, e.g. maven-release-plugin-2.0.jar:

<goalPrefix>release</goalPrefix>
...
  <mojos>
    <mojo>
      <goal>help</goal>
      ...
    <mojo>
      <goal>prepare</goal>
      ...

Or do you mean, how Maven discovers which plugins are available? Then the answer is:

  • There are two default groups where plugins are searched, org.apache.maven.plugins and org.codehaus.mojo
  • For your own plugin you may want to use name ${prefix}-maven-plugin, e.g. cap4j-maven-plugin
  • You can keep your name cap4j, but then put the plugin description to your POM, under <plugins>
  • If you want your build to work at other machines, they should point <pluginRepositories> in POM or in settings.xml to your plugin repository
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top