1

I'm using Eclipse Kepler with M2E. I've created an empty Eclipse project, directly converted to a Maven project. The pom.xml is cleaned: no dependency or build section, no parent POM. The Maven settings.xml is the default one: no info included.

When consulting the Effective POM thanks to M2E, lots of plugins are present:

<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <modelVersion>4.0.0</modelVersion>
  <groupId>testTCO</groupId>
  <artifactId>testTCO</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <repositories>
    <repository>
      <snapshots>
        <enabled>false</enabled>
      </snapshots>
      <id>central</id>
      <name>Central Repository</name>
      <url>http://repo.maven.apache.org/maven2</url>
    </repository>
  </repositories>
  <pluginRepositories>
    <pluginRepository>
      <releases>
        <updatePolicy>never</updatePolicy>
      </releases>
      <snapshots>
        <enabled>false</enabled>
      </snapshots>
      <id>central</id>
      <name>Central Repository</name>
      <url>http://repo.maven.apache.org/maven2</url>
    </pluginRepository>
  </pluginRepositories>
  <build>
    <sourceDirectory>C:\stuff\eclipse-jee-kepler_64\workspace\wosp\testTCO\src\main\java</sourceDirectory>
    <scriptSourceDirectory>C:\stuff\eclipse-jee-kepler_64\workspace\wosp\testTCO\src\main\scripts</scriptSourceDirectory>
    <testSourceDirectory>C:\stuff\eclipse-jee-kepler_64\workspace\wosp\testTCO\src\test\java</testSourceDirectory>
    <outputDirectory>C:\stuff\eclipse-jee-kepler_64\workspace\wosp\testTCO\target\classes</outputDirectory>
    <testOutputDirectory>C:\stuff\eclipse-jee-kepler_64\workspace\wosp\testTCO\target\test-classes</testOutputDirectory>
    <resources>
      <resource>
        <directory>C:\stuff\eclipse-jee-kepler_64\workspace\wosp\testTCO\src\main\resources</directory>
      </resource>
    </resources>
    <testResources>
      <testResource>
        <directory>C:\stuff\eclipse-jee-kepler_64\workspace\wosp\testTCO\src\test\resources</directory>
      </testResource>
    </testResources>
    <directory>C:\stuff\eclipse-jee-kepler_64\workspace\wosp\testTCO\target</directory>
    <finalName>testTCO-0.0.1-SNAPSHOT</finalName>
    <pluginManagement>
      <plugins>
        <plugin>
          <artifactId>maven-antrun-plugin</artifactId>
          <version>1.3</version>
        </plugin>
        <plugin>
          <artifactId>maven-assembly-plugin</artifactId>
          <version>2.2-beta-5</version>
        </plugin>
        <plugin>
          <artifactId>maven-dependency-plugin</artifactId>
          <version>2.1</version>
        </plugin>
        <plugin>
          <artifactId>maven-release-plugin</artifactId>
          <version>2.0</version>
        </plugin>
      </plugins>
    </pluginManagement>
    <plugins>
      <plugin>
        <artifactId>maven-clean-plugin</artifactId>
        <version>2.4.1</version>
        <executions>
          <execution>
            <id>default-clean</id>
            <phase>clean</phase>
            <goals>
              <goal>clean</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <artifactId>maven-resources-plugin</artifactId>
        <version>2.5</version>
        <executions>
          <execution>
            <id>default-testResources</id>
            <phase>process-test-resources</phase>
            <goals>
              <goal>testResources</goal>
            </goals>
          </execution>
          <execution>
            <id>default-resources</id>
            <phase>process-resources</phase>
            <goals>
              <goal>resources</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <artifactId>maven-jar-plugin</artifactId>
        <version>2.3.2</version>
        <executions>
          <execution>
            <id>default-jar</id>
            <phase>package</phase>
            <goals>
              <goal>jar</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>2.3.2</version>
        <executions>
          <execution>
            <id>default-compile</id>
            <phase>compile</phase>
            <goals>
              <goal>compile</goal>
            </goals>
          </execution>
          <execution>
            <id>default-testCompile</id>
            <phase>test-compile</phase>
            <goals>
              <goal>testCompile</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.10</version>
        <executions>
          <execution>
            <id>default-test</id>
            <phase>test</phase>
            <goals>
              <goal>test</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <artifactId>maven-install-plugin</artifactId>
        <version>2.3.1</version>
        <executions>
          <execution>
            <id>default-install</id>
            <phase>install</phase>
            <goals>
              <goal>install</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <artifactId>maven-deploy-plugin</artifactId>
        <version>2.7</version>
        <executions>
          <execution>
            <id>default-deploy</id>
            <phase>deploy</phase>
            <goals>
              <goal>deploy</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <artifactId>maven-site-plugin</artifactId>
        <version>3.0</version>
        <executions>
          <execution>
            <id>default-site</id>
            <phase>site</phase>
            <goals>
              <goal>site</goal>
            </goals>
            <configuration>
              <outputDirectory>C:\stuff\eclipse-jee-kepler_64\workspace\wosp\testTCO\target\site</outputDirectory>
              <reportPlugins>
                <reportPlugin>
                  <groupId>org.apache.maven.plugins</groupId>
                  <artifactId>maven-project-info-reports-plugin</artifactId>
                </reportPlugin>
              </reportPlugins>
            </configuration>
          </execution>
          <execution>
            <id>default-deploy</id>
            <phase>site-deploy</phase>
            <goals>
              <goal>deploy</goal>
            </goals>
            <configuration>
              <outputDirectory>C:\stuff\eclipse-jee-kepler_64\workspace\wosp\testTCO\target\site</outputDirectory>
              <reportPlugins>
                <reportPlugin>
                  <groupId>org.apache.maven.plugins</groupId>
                  <artifactId>maven-project-info-reports-plugin</artifactId>
                </reportPlugin>
              </reportPlugins>
            </configuration>
          </execution>
        </executions>
        <configuration>
          <outputDirectory>C:\stuff\eclipse-jee-kepler_64\workspace\wosp\testTCO\target\site</outputDirectory>
          <reportPlugins>
            <reportPlugin>
              <groupId>org.apache.maven.plugins</groupId>
              <artifactId>maven-project-info-reports-plugin</artifactId>
            </reportPlugin>
          </reportPlugins>
        </configuration>
      </plugin>
    </plugins>
  </build>
  <reporting>
    <outputDirectory>C:\stuff\eclipse-jee-kepler_64\workspace\wosp\testTCO\target\site</outputDirectory>
  </reporting>
</project>

For example the version 2.5 of the plugin maven-resources-plugin is loaded. Why this version and not a more recent one?

I know that I can overwrite this by specifying the plugin and the required version in the pom.xml, but I would like to know how these default version values are loaded.

The super POM includes a part of the content of the effective POM but most of the plugins seem to come from nowhere.

Tunaki
  • 132,869
  • 46
  • 340
  • 423
ThCollignon
  • 976
  • 3
  • 14
  • 31

2 Answers2

2

This is a combination of the Super POM and Maven default bindings.

The Super POM is a special POM that all POM implicitly inherit from. It defines various default properties that all Maven projects will share. It is also used to fix plugin versions for the most commonly used plugins. For Maven 3.3.9, this POM only defines those versions.

<plugin>
  <artifactId>maven-antrun-plugin</artifactId>
  <version>1.3</version>
</plugin>
<plugin>
  <artifactId>maven-assembly-plugin</artifactId>
  <version>2.2-beta-5</version>
</plugin>
<plugin>
  <artifactId>maven-dependency-plugin</artifactId>
  <version>2.8</version>
</plugin>
<plugin>
  <artifactId>maven-release-plugin</artifactId>
  <version>2.3.2</version>
</plugin>

But note the comment in this:

<!-- NOTE: These plugins will be removed from future versions of the super POM -->
<!-- They are kept for the moment as they are very unlikely to conflict with lifecycle mappings (MNG-4453) -->

which links to the Maven issue MNG-4453. Nowadays, plugin versions are defined inside default bindings for a given lifecycle and it is likely that what is currently present in the Super POM will be removed.

Those bindings can be found in the META-INF/plexus/default-bindings.xml file. For reference, this is what it looks like for the jar packaging:

<phases>
  <process-resources>
    org.apache.maven.plugins:maven-resources-plugin:2.6:resources
  </process-resources>
  <compile>
    org.apache.maven.plugins:maven-compiler-plugin:2.5.1:compile
  </compile>
  <process-test-resources>
    org.apache.maven.plugins:maven-resources-plugin:2.6:testResources
  </process-test-resources>
  <test-compile>
    org.apache.maven.plugins:maven-compiler-plugin:2.5.1:testCompile
  </test-compile>
  <test>
    org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test
  </test>
  <package>
    org.apache.maven.plugins:maven-jar-plugin:2.4:jar
  </package>
  <install>
    org.apache.maven.plugins:maven-install-plugin:2.4:install
  </install>
  <deploy>
    org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy
  </deploy>
</phases>

Default version of plugins are bound to a specific phase of the packaging and your build will inherit from those.

Tunaki
  • 132,869
  • 46
  • 340
  • 423
  • hi @Tunaki, I have two projects and in both of them, they don't define the "maven-jar-plugin" explicitly in any pom file. Not even in the main pom.xml. But when building with maven, project 1 picks the "maven-jar-plugin" version 2.4 and the other one picks "maven-jar-plugin" version 2.6. In an OpenJDK 11 environment, the project which picks jar plugin version 2.6 never works and the build fails. Do you have any idea how this happens? – Agent47 Feb 06 '23 at 11:03
1

The super pom defines some parts (folder structure) but the life cycle binding defines other parts like the binding to the appropriate life cycle phases. The life cycle phases itself are defined here.

The versions of the plugins depend on which version of Maven you are using cause the life cycle binding is being updated. If you like to be sure which version of a plugin is being used the best practice is to define all plugins you are using via pluginManagement in your pom which should be done in a corporate pom file to avoid duplication.

khmarbaise
  • 92,914
  • 28
  • 189
  • 235