dokaspar
dokaspar

Reputation: 8624

How to avoid Maven plugin defined in parent to be overridden by child?

The Maven project I'm working on inherits from a parent POM where some project-wide variables are calculated by executing the gmaven-plugin during the validate phase:

Parent POM:

<plugin>
  <groupId>org.codehaus.gmaven</groupId>
  <artifactId>gmaven-plugin</artifactId>
  <version>1.5-jenkins-1</version>
  <executions>
    <execution>
      <phase>validate</phase>
      <goals><goal>execute</goal></goals>
      <configuration>
        <providerSelection>2.0</providerSelection>
        <source>
          project.properties.put("test.property1", "123");
        </source>
      </configuration>
    </execution>
  </executions>
</plugin>

Now I wanted to use the gmaven-plugin also in a child POM to calculate and set some additional parameters:

Child POM:

<plugin>
  <groupId>org.codehaus.gmaven</groupId>
  <artifactId>gmaven-plugin</artifactId>
  <version>1.5-jenkins-1</version>
  <executions>
    <execution>
      <phase>validate</phase>
      <goals><goal>execute</goal></goals>
      <configuration>
        <providerSelection>2.0</providerSelection>
        <source>
          project.properties.put("test.property2", "abc");
        </source>
      </configuration>
    </execution>
  </executions>
</plugin>

However, this causes the plugin defined in the parent to disappear / to be overwritten. The effective POM contains only the plugin defined in the child and the test.property1 ends up as null.

How can I execute a Maven plugin in the parent and another in the child without that they interfere with each other?

Upvotes: 1

Views: 863

Answers (3)

question_maven_com
question_maven_com

Reputation: 2475

add : 

    <inherited>true</inherited>

like : 
    <groupId>org.codehaus.gmaven</groupId>
      <artifactId>gmaven-plugin</artifactId>
      <version>1.5-jenkins-1</version>
     <inherited>true</inherited>

https://maven.apache.org/guides/mini/guide-configuring-plugins.html#Using_the_inherited_Tag_In_Build_Plugins

Upvotes: 2

Anatrollik
Anatrollik

Reputation: 351

As far as I remember you could just configure another Executions section in child's pom and all references to parent's plugin would disappear.

Upvotes: 0

Michael-O
Michael-O

Reputation: 18430

Read this blog entry how to merge configs. This might resolve your problem.

Upvotes: 1

Related Questions