Ответ 1
Вы правы, по умолчанию Maven будет включать все настройки, которые вы настроили. Вот как я раньше занимался этой ситуацией.
<pluginManagement>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>some-maven-plugin</artifactId>
<version>1.0</version>
<executions>
<execution>
<id>first-execution</id>
<phase>none</phase>
<goals>
<goal>some-goal</goal>
</goals>
<configuration>
<!-- plugin config to share -->
</configuration>
</execution>
<execution>
<id>second-execution</id>
<phase>none</phase>
<goals>
<goal>other-goal</goal>
</goals>
<configuration>
<!-- plugin config to share -->
</configuration>
</execution>
</executions>
</plugin>
</pluginManagement>
Обратите внимание, что выполнение привязано к фазе none
. В дочернем случае вы включаете части, которые должны выполняться следующим образом:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>some-maven-plugin</artifactId>
<executions>
<execution>
<id>first-execution</id> <!-- be sure to use ID from parent -->
<phase>prepare-package</phase> <!-- whatever phase is desired -->
</execution>
<!-- enable other executions here - or don't -->
</executions>
</plugin>
Если дочерний элемент явно не привязывает выполнение к фазе, он не будет работать. Это позволяет вам выбирать желаемые исполнения.