I want to define different executions for plugins in the pluginManagement of my parent pom, and then bind specific executions to stages in the child pumps. I see inconsistent behavior depending on the plugin used and the location of the pluginManagement section.
In this first example, pluginManagement is in the parent pom, which defines 2 executions for the compiler plugin and 2 executions for the antrun plugin.
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <name>master-pom</name> <modelVersion>4.0.0</modelVersion> <groupId>plugin.test</groupId> <artifactId>master-pom</artifactId> <packaging>pom</packaging> <version>1.0.0-SNAPSHOT</version> <build> <pluginManagement> <plugins> <plugin> <artifactId>maven-compiler-plugin</artifactId> <executions> <execution> <id>execution-1</id> <phase>none</phase> <goals> <goal>compile</goal> </goals> <configuration> <source>1.6</source> <target>1.6</target> <includes> <include>**/*</include> </includes> </configuration> </execution> <execution> <id>execution-2</id> <phase>none</phase> <goals> <goal>compile</goal> </goals> <configuration> <source>1.5</source> <target>1.5</target> <includes> <include>**/*</include> </includes> </configuration> </execution> </executions> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-antrun-plugin</artifactId> <version>1.7</version> <executions> <execution> <id>execution-1</id> <goals> <goal>run</goal> </goals> <configuration> <target> <echo message="execution 1"/> </target> </configuration> </execution> <execution> <id>execution-2</id> <goals> <goal>run</goal> </goals> <configuration> <target> <echo message="execution 1"/> </target> </configuration> </execution> </executions> </plugin> </plugins> </pluginManagement> </build>
And baby pom:
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <name>build</name> <modelVersion>4.0.0</modelVersion> <groupId>plugin.test</groupId> <artifactId>build</artifactId> <version>1.0.0-SNAPSHOT</version> <packaging>pom</packaging> <parent> <groupId>plugin.test</groupId> <artifactId>master-pom</artifactId> <version>1.0.0-SNAPSHOT</version> <relativePath>./master-pom.xml</relativePath> </parent> <build> <plugins> <plugin> <artifactId>maven-compiler-plugin</artifactId> <executions> <execution> <id>execution-1</id> <phase>generate-sources</phase> </execution> </executions> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-antrun-plugin</artifactId> <executions> <execution> <id>execution-1</id> <phase>generate-sources</phase> </execution> </executions> </plugin> </plugins> </build>
Running "mvn clean install" on the child pom will run both the execution of the compiler plugin and only the first execution of the antrun plugin, although only one execution of each of them was associated with a phase.
Now move the pluginManagement file to the child pom:
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <name>build</name> <modelVersion>4.0.0</modelVersion> <groupId>plugin.test</groupId> <artifactId>build</artifactId> <version>1.0.0-SNAPSHOT</version> <packaging>pom</packaging> <build> <pluginManagement> <plugins> <plugin> <artifactId>maven-compiler-plugin</artifactId> <executions> <execution> <id>execution-1</id> <phase>none</phase> <goals> <goal>compile</goal> </goals> <configuration> <source>1.6</source> <target>1.6</target> <includes> <include>**/*</include> </includes> </configuration> </execution> <execution> <id>execution-2</id> <phase>none</phase> <goals> <goal>compile</goal> </goals> <configuration> <source>1.5</source> <target>1.5</target> <includes> <include>**/*</include> </includes> </configuration> </execution> </executions> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-antrun-plugin</artifactId> <version>1.7</version> <executions> <execution> <id>execution-1</id> <goals> <goal>run</goal> </goals> <configuration> <target> <echo message="execution 1"/> </target> </configuration> </execution> <execution> <id>execution-2</id> <goals> <goal>run</goal> </goals> <configuration> <target> <echo message="execution 2"/> </target> </configuration> </execution> </executions> </plugin> </plugins> </pluginManagement> <plugins> <plugin> <artifactId>maven-compiler-plugin</artifactId> <executions> <execution> <id>execution-1</id> <phase>generate-sources</phase> </execution> </executions> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-antrun-plugin</artifactId> <executions> <execution> <id>execution-1</id> <phase>generate-sources</phase> </execution> </executions> </plugin> </plugins> </build>
This pom gives the desired behavior, which runs only the 1st execution for each plugin. The compiler plugin (and most others) only works correctly when pluginManagement is in the same folder and each execution is tied to phase = no (probably because it associates the execution with the default phase). In any case, the antrun plugin works correctly.
How can I achieve this by having the pluginManagement section in the parent pump and not requiring special linking of the undesired executions with the phase = none in the child pumps? Is this a mistake in Maven or is this behavior somehow justified? I tried this on Maven 3.0.4 and Maven 2.2.1 with the same results.
maven
Rigas Grigoropoulos Nov 06 2018-12-11T00: 00Z
source share