Raw
Raw

Reputation: 675

pluginManagement does not work

This is the pluginManagement in the parent POM, and it can be executed by child project that no plugins defined in child project, why??

 <build>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                        <configuration>
                            <classifier>exec</classifier>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </pluginManagement>
</build>

But if I remove this plugin from parant POM then the child project can't be executed.

Upvotes: 2

Views: 2383

Answers (1)

carlspring
carlspring

Reputation: 32587

In your parent POM, you need to have something like:

 <build>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>1.5.7.RELEASE</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                        <configuration>
                            <classifier>exec</classifier>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </pluginManagement>
</build>

Then in your project that extends this POM, you just need to do:

 <build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

The idea here is that you don't need to have the same code copied all over the place. You define the settings in one central place and then just extend them.

In your original code, you didn't have the <version/> defined. Usually, in parent POM-s you'd like to control the versions of <dependencies/> and <plugins/>. For dependencies you can also define things like <exclusions/> and <scope/>.

For plugins, you could have the same configuration defined centrally and then, if a case arises where you'd like it to be slightly different, you can just apply the necessary changes in the extending POM.

If in your parent POM you also have a definition of <plugins/> outside the <pluginManagement/> section, then those plugins will be invoked for any project extending this parent.

Upvotes: 1

Related Questions