Add execution to plugin defined in parent pom

83 Views Asked by At

I have a parent pom.xml file which has a build section like so:

<build>
  <pluginManagement>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-checkstyle-plugin</artifactId>
        <version>${maven-checkstyle-plugin.version}</version>
        <inherited>true</inherited>
        <dependencies>
          <dependency>
            <groupId>com.puppycrawl.tools</groupId>
            <artifactId>checkstyle</artifactId>
            <version>${checkstyle.version}</version>
          </dependency>
        </dependencies>
      </plugin>
    </plugins>
  </pluginManagement>
</build>

In the child pom, I want to effectively add an executions node to the plugin, but without having to respecify the version and dependencies nodes - is there a way to do this?

1

There are 1 best solutions below

0
Slawomir Jaranowski On

You can simply add in your child pom:

<build>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-checkstyle-plugin</artifactId>
      <executions>
        <execution>
          <id>checkstyle-check</id>
          <goals>
            <goal>check</goal>
          </goals>
        </execution>
      </executions>
    </plugin>
  <plugins>
<build>

The difference is path where you define plugin

  • in build/pluginManagement/plugins - you have only configuration
  • in build/plugins - you declare what you want to execute

Even more you can also move executions to pluginManagement, then in child you can have:

<build>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-checkstyle-plugin</artifactId>
    </plugin>
  <plugins>
<build>

The nodes for plugin configuration from pluginManagement and plugins and all child are merged to effective pom.

You can always check how your effective pom will look:

mvn help:effective-pom