Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Append or merge default maven plugin configuration

Is it possible to not override but merge or append to default plugin configuration in Apache Maven just like it's possible with parent POM configuration elements?

like image 659
sevo Avatar asked Apr 13 '16 09:04

sevo


People also ask

What are the correct type of Maven plugins?

Introduction. In Maven, there are two kinds of plugins, build and reporting: Build plugins are executed during the build and configured in the <build/> element. Reporting plugins are executed during the site generation and configured in the <reporting/> element.

How do I override plugin from parent pom?

Overriding configurations from a parent pom can be done by adding the combine. self="override" attribute to the element in your pom. It appears that for Maven2. 2.1 if you do this in a profile it doesn't merge with plugins defined in parent profiles but overrides them.

Are plugins inherited from parent pom?

1. Overview. Maven allows us to build a project using the concept of inheritance. When a parent POM defines a plugin, all of the child modules inherit it.

What is the correct syntax for executing a Maven plugin?

Usage of a Maven Plugin xml you can use the shorthand notation to execute the plugin: mvn <prefix>:<goal> , commonly the “prefix” is the artifact ID minus the “-maven-plugin”.

How do I Configure my Maven plugins?

Maven plugins (build and reporting) are configured by specifying a <configuration> element where the child elements of the <configuration> element are mapped to fields, or setters, inside your Mojo (remember that a plug-in consists of one or more Mojos where a Mojo maps to a goal).

What is generic configuration in Maven?

Generic Configuration. Maven plugins (build and reporting) are configured by specifying a <configuration> element where the child elements of the <configuration> element are mapped to fields, or setters, inside your Mojo (remember that a plug-in consists of one or more Mojos where a Mojo maps to a goal).

How to configure Maven plugin in Mojo?

Maven plugins (build and reporting) are configured by specifying a <configuration> element where the child elements of the <configuration> element are mapped to fields, or setters, inside your Mojo. (Remember that a plug-in consists of one or more Mojos where a Mojo maps to a goal.) Say, for example, you have a Mojo that performs a query ...

What version of Maven filtering does the Maven-assembly-plugin use?

To handle filtering this version of Maven Assembly Plugin uses Maven Filtering 3.1.1. To handle archiving this version of Maven Assembly Plugin uses Maven Archiver 3.5.0. This document is intended to provide instructions for using the maven-assembly-plugin.


1 Answers

I'm note sure if i understand your questions correctly:

If you like for example to change the configuration of an already defined plugin you should be aware that you need to use the correct execution id which can be looked at during a default build which is printed out in the log output (something like this):

[INFO] --- maven-clean-plugin:3.0.0:clean (default-clean) @ parent ---
[INFO]
[INFO] --- maven-enforcer-plugin:1.4.1:enforce (enforce-maven) @ parent ---
[INFO]

The value in braces gives the hint: default-clean can now be used to add information to the configuration or also to change behaviour:

<plugins>
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-clean-plugin</artifactId>
    <executions>
      <execution>
        <id>default-clean</id>
        <configuration>
         <.. combine.children="append">
         </...>
        </configuration>

See more explanations following.

You can do this if you need. Lets say you have defined the following in a parent pom file:

<plugin>
 <groupId>..</groupId>
 <artifactId>..</artifactId>
 <configuration>
   <values>
     <value>First</value>
   </values>
 </configuration>
</plugin>

In an inheriting pom file you can now write the following:

<plugin>
 <groupId>..</groupId>
 <artifactId>..</artifactId>
 <configuration>
   <values combine.children="append">
     <value>Second</value>
   </values>
 </configuration>
</plugin>

Or if you do something different:

<plugin>
 <groupId>..</groupId>
 <artifactId>..</artifactId>
 <configuration>
   <values combine.children="override">
     <value>Second</value>
   </values>
 </configuration>
</plugin>

or you can give explicitly what is already the default:

<plugin>
 <groupId>..</groupId>
 <artifactId>..</artifactId>
 <configuration>
   <values combine.children="merge">
     <value>Second</value>
   </values>
 </configuration>
</plugin>

This is documented in the pom reference.

like image 60
khmarbaise Avatar answered Oct 19 '22 14:10

khmarbaise