13

I'm using pluginManagement element in my parent pom.xml to configure plugins for all its children. For example, I have the following configuration:

<pluginManagement>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-resources-plugin</artifactId>
        <version>2.4.3</version>
        <executions>
            <execution>
                <id>copy-artifacts</id>
                <phase>install</phase>
                <goals>
                    <goal>copy-resources</goal>
                </goals>
                <configuration>
                    <outputDirectory>some/where/else</outputDirectory>
                    <resources>
                        <resource>
                            <directory>some/another/resource</directory>
                        </resource>
                    </resources>
                </configuration>
            </execution>
        </executions>
    </plugin>

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <version>2.4</version>
        <executions>
            <execution>
                <id>copy-dependencies</id>
                <phase>install</phase>
                <goals>
                    <goal>copy-dependencies</goal>
                </goals>
                <configuration>
                    <outputDirectory>deps/dir</outputDirectory>
                </configuration>
            </execution>
        </executions>
    </plugin>
</pluginManagement>

The official documentation states that a plugin configured in pluginManagement still has to be added to plugins element in children poms. Indeed, if I remove this from child pom:

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

then maven-dependency-plugin stops firing at install phase. However, it seems that it does not affect some other plugins, namely, maven-resource-plugin. Even if I do not have

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

in my child pom, its copy-resources goal still fires at install phase and performs the work it is configured to do.

Why is this behavior present? Is there a list of plugins which are inherited always, or maybe I'm missing something?

Vladimir Matveev
  • 120,085
  • 34
  • 287
  • 296

2 Answers2

11

The whole POM isn't visible; but given the behavior you're describing this is a jar, war, or ear, correct? The resource plugin is defined for those packaging types by default. It includes an execution that copies resources (as described by @maba).

Since the plugin definition is included in your child POM (even though YOU didn't put it there directly), Maven merges the execution defined in the <pluginManagement> section with the execution provided by Maven.

There is documentation describing the default lifecycle bindings by packaging type. Note the dependency plugin isn't mentioned; but resources is; that's why you observe the difference. Running with -X will show the plugin executions.

user944849
  • 14,524
  • 2
  • 61
  • 83
  • 1
    Yes, my pom packaging is jar. So, it is because `resources-plugin` is included automatically it also automatically inherits all configuration from `pluginManagement`, right? Then, I think, I found the answer. I thought that it was something like this. Thank you very much! – Vladimir Matveev Oct 02 '12 at 15:12
  • 1
    @VladimirMatveev Yes there are other plugins that are included by default as well. One obvious is `maven-compiler-plugin`. – maba Oct 02 '12 at 15:15
  • 1
    @VladimirMatveev I guess you can find the core plugins here: [Maven Available Plugins](http://maven.apache.org/plugins/index.html). – maba Oct 02 '12 at 15:17
1

Maven always copies resources that are inside src/main/resources by default.

From Maven Getting Started Guide:

The simple rule employed by Maven is this: any directories or files placed within the ${basedir}/src/main/resources directory are packaged in your JAR with the exact same structure starting at the base of the JAR.

maba
  • 47,113
  • 10
  • 108
  • 118
  • I know about `src/main/resources`, but my configuration (maybe I should't have replaced it by ellipsis, I just thought that it is unneccessary waste of space) copies several files to different locations, and it is this what works despite that the plugin is removed from child pom. I've updated my question on this matter. – Vladimir Matveev Oct 02 '12 at 15:04