Skip to content

[SCM]Develop Plugin for Maven

lifuzu edited this page Nov 22, 2013 · 2 revisions

Create a new plugin project:

mvn archetype:generate \
  -DgroupId=sample.plugin \
  -DartifactId=hello-maven-plugin \
  -DarchetypeGroupId=org.apache.maven.archetypes \
  -DarchetypeArtifactId=maven-archetype-plugin

Tune the compiler to build it:

<project>
  <build>
    <pluginManagement>
      <plugins>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>3.1</version>
          <configuration>
            <!-- put your configurations here -->
          </configuration>
        </plugin>
      </plugins>
    </pluginManagement>
    ...
  </build>
</project>

Compile, test, package, and install the new plugin:

mvn compile test package install

Added it as another application's dependency

<project>
  <build>
  ...
    <plugins>
      <plugin>
        <groupId>sample.plugin</groupId>
        <artifactId>hello-maven-plugin</artifactId>
        <version>1.0-SNAPSHOT</version>
        <executions>
          <execution>
            <phase>compile</phase>
            <goals>
              <goal>touch</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
  ...
</project>

Run it from another application

mvn sample.plugin:hello-maven-plugin:touch

OR

mvn package

SAMPLE REPO:

https://github.com/lifuzu/study-maven

#REFERENCE:

  1. http://maven.apache.org/guides/plugin/guide-java-plugin-development.html

Clone this wiki locally