Search code examples
mavencoberturamaven-cobertura-plugin

cobertura-maven-plugin 2.6 is used despite 2.7 is configured


I have this section in my POM:

<reporting>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>cobertura-maven-plugin</artifactId>
            <version>2.7</version>
        </plugin>
    </plugins>
</reporting>

When i invoke this command from terminal:

mvn clean cobertura:cobertura

cobertura-maven-plugin version 2.6 is used:

[INFO] >>> cobertura-maven-plugin:2.6:cobertura (default-cli) > [cobertura]test @ myproject >>>

If I add this section too:

<build>
    <!-- ... -->
    <plugins>
        <!-- ... -->
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>cobertura-maven-plugin</artifactId>
            <version>2.7</version>
        </plugin>
    </plugins>
</build>

Version 2.7 is used as intended. Is this normal?


Solution

  • In the first example you've added Cobertura in version 2.7 only to reports generated during site phase. Goal cobertura:cobertura is bound to test phase, which is separate lifecycle.

    In order to solve such problems, there is pluginManagement section. Add the following to POM:

    <pluginManagement>
      <plugins>
        <plugin>
          <groupId>org.codehaus.mojo</groupId>
          <artifactId>cobertura-maven-plugin</artifactId>
          <version>2.7</version>
        </plugin>
      </plugins>
    </pluginManagement>
    

    and everywhere else use Cobertura without providing version:

    <build>
        <!-- ... -->
        <plugins>
            <!-- ... -->
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>cobertura-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
    <!-- ... -->
    <reporting>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>cobertura-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </reporting>