1

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?

Michal Kordas
  • 10,475
  • 7
  • 58
  • 103
WonderCsabo
  • 11,947
  • 13
  • 63
  • 105

1 Answers1

1

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>
Michal Kordas
  • 10,475
  • 7
  • 58
  • 103
  • I see, thanks. And where 2.6 version is coming from? It is not in the super-POM, maybe defined in Maven itself? – WonderCsabo Apr 19 '15 at 13:35
  • 1
    Here are the logs: ```[DEBUG] Resolved plugin prefix cobertura to org.codehaus.mojo:cobertura-maven-plugin from repository central. [DEBUG] Resolving plugin version for org.codehaus.mojo:cobertura-maven-plugin. [DEBUG] Resolved plugin version for org.codehaus.mojo:cobertura-maven-plugin to 2.6 from repository central (http://repo.maven.apache.org/maven2, releases).``` But I'm not sure why it fetches 2.6 by default from Maven Central. – Michal Kordas Apr 19 '15 at 13:58
  • 1
    `maven-metadata-central.xml` for cobertura plugin has `2.6` tag. Here is possible explanation: https://support.sonatype.com/entries/23778606-Why-are-the-latest-and-release-tags-in-maven-metadata-xml-not-being-updated-after-deploying-artifact – Michal Kordas Apr 19 '15 at 14:07