Monday 24 April 2017

Maven plugin


  1. Define one mojo per plugin goal
  2. Include components.xml to define a lifecycle
  3. Use defaults in mojo
  4. Add a parent POM for common configuration
  5. Define  main artifact with:

    @Parameter(defaultValue = "${project}", readonly = true, required = true)
    private MavenProject project;...project.getArtifact().setFile(xyz);
    ...
  6. Add the following in components.xml:

    <component>
      <role>org.codehaus.plexus.archiver.UnArchiver</role>
      <role-hint>xyz</role-hint>
      <implementation>org.codehaus.plexus.archiver.zip.ZipUnArchiver</implementation>
      <instantiation-strategy>per-lookup</instantiation-strategy>
    </component>
  7. Add the following (plugin level!) dependency in projects using unpack-dependencies:


    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-dependency-plugin</artifactId>
      <version>2.9</version>
      <dependencies>
        <dependency>
          <groupId>com.mycompany.myteam</groupId>
          <artifactId>xyz-maven-plugin</artifactId>
          <version>1.0.0-SNAPSHOT</version>
        </dependency>
      </dependencies>
    </plugin>