maven build phase plugine(clover duplicate class)

When using clover2 in CI build, it might throw duplicate class error if using: mvn clover2:setup test clover2:aggregate clover2:clover.

The reason is the clover2:setup is by default in the generate-source phase will copy the src to target/clover/src-instrumented and the test will also run the generate source and compile. Now there end up to be 2 source and duplicate class error is thrown.

One solution is to bind the clover2:setup to the process-source phase.

<executions>
        <execution>
            <id>instrument</id>
            <phase>process-sources</phase>
            <goals>
                <goal>setup</goal>
            </goals>
        </execution>
    </executions>

More about maven phase and plugin

Maven helps you build a project. The way it does that is through the build lifecycle and theplugins.

The lifecycle is made of phases that you can call explicitly on the command line, for example:

mvn package

package is a phase part of the default build lifecycle, like compile ordeploy. All the phases of the default lifecycle can be found in thereference. At each phase, Maven calls a goal in a plugin that does something for you. For example, the maven-compiler-plugin has acompile goal that compiles your java code during the compile phase of the lifecycle. You can also explicitly call a plugin on the command line, like:

mvn clean:clean

which calls the clean goal on the maven-clean-plugin. By default this goal is bound to the clean phase, so you can call it by executing mvn clean. You can call any plugin by using its group id, its artifact id, its version and the goal you want to execute, e.g.:

mvn org.codehaus.mojo:versions-maven-plugin:2.1:set -DnewVersion=1.2.3

(A plugin named blah-maven-plugin can be called by the shortened version of its name, blah. See also the Guide to Developing Java Plugins)

To “bind” a plugin goal to a phase, you just need to define your plugin in your pom.xml, and define its execution to a phase of the lifecycle:

      <plugin>
        <groupId>org.mirah.maven</groupId>
        <artifactId>maven-mirah-plugin</artifactId>
        <version>1.1-SNAPSHOT</version>
        <executions>
          <execution>
            <phase>compile</phase>
            <goals><goal>compile</goal></goals>
          </execution>
        </executions>
      </plugin>

Here we are attaching the mirah compile goal to the compile phase of the lifecycle. When Maven executes the compile phase, it will the compile the Mirah code for us.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s