0

If I have two maven plugins, where A depends on B and B has configuration parameters, how and where should I define configuration for B?

I could think of three solutions, which of one I know is not applicable, and I'm not sure which one works, or there are any more possiblities. Unfortunately, I couldn't find any example even for this simple case.

Try 1 (not possible)

Put <configuration> under dependencies. This is not possible as a <dependency> tag cannot contain a <configuration> tag (see xsd).

<plugin>
    <groupId>A</groupId>
    <artifactId>A</artifactId>
    <version>1.0.0</version>
    <dependencies>
        <dependency>
            <groupId>B</groupId>
            <artifactId>B</artifactId>
            <version>1.0.0</version>
            <configuration>
                <paramForB><param>bbb</param></paramForB>
            </configuration>
        </dependency>
    </dependencies>
</plugin>

Try 2

Put the configuration parameter under the config of A.

<plugin>
    <groupId>A</groupId>
    <artifactId>A</artifactId>
    <version>1.0.0</version>
    <dependencies>
        <dependency>
            <groupId>B</groupId>
            <artifactId>B</artifactId>
            <version>1.0.0</version>
        </dependency>
    </dependencies>
    <configuration>
        <paramForB><param>bbb</param></paramForB>
    </configuration>
</plugin>

Try 3

Introduce B as a separate plugin with the configuration I need.

<plugin>
    <groupId>B</groupId>
    <artifactId>B</artifactId>
    <version>1.0.0</version>
    <configuration>
        <paramForB><param>bbb</param></paramForB>
    </configuration>
</plugin>
<plugin>
    <groupId>A</groupId>
    <artifactId>A</artifactId>
    <version>1.0.0</version>
    <dependencies>
        <dependency>
            <groupId>B</groupId>
            <artifactId>B</artifactId>
            <version>1.0.0</version>
        </dependency>
    </dependencies>
</plugin>

Further questions (just curious)

  1. Also, what if B depends on C. How should I configure C?
  2. And if I have a maven plugin X which also depends on B but would use it with other configuration: can I do that?
n-a-sz
  • 3
  • 5
  • If you have two plugins they can't depend on each other...Furthermore the dependencies of a plugin is something different...and you can only give configurations to plugins but not to dependencies. Maybe you can make a more concrete example what you are trying to accomplish.... – khmarbaise Mar 21 '18 at 14:56
  • Thanks for your comment, I've read more about the topic and found my answer. – n-a-sz Mar 23 '18 at 10:14

2 Answers2

0

In maven you have profiles and properties. First start with properties:

Project B

<properties>
   <customeParameter>parameterInB</customeParameter>
</properties>
<plugin>
    <groupId>A</groupId>
    <artifactId>A</artifactId>
    <version>1.0.0</version>
    <dependencies>
        <dependency>
            <groupId>B</groupId>
            <artifactId>B</artifactId>
            <version>1.0.0</version>
            <configuration>
                <paramForB>${customeParameter}</paramForB>
            </configuration>
        </dependency>
    </dependencies>
</plugin>

Project A

<properties>
   <customeParameter>overrideInA</customeParameter>
</properties>

See my answer to question: How to get a command-line property to overwrite a maven property

My example will work if project B is a parent for project A. If not, please define share configuration in parent pom (which will be parent for A and B) and parametrize it. Then in child you can define in "properties" section values for this configuration.

Andrzej Jozwik
  • 14,331
  • 3
  • 59
  • 68
  • Thanks for your answer! I didn't know that only properties can be overriden in command line. Maven says, I cannot define the tag under a tag, I have already tried that. In the meantime, I got a deeper understanding how the maven plugins work so I posted the answer, I was looking for. – n-a-sz Mar 23 '18 at 10:11
0

The answer is basically Try 2, i.e., add configurations of B to the plugin usage A, but it depends on how plugin A was implemented as it its responsibility to pass the parameters.

n-a-sz
  • 3
  • 5