7

I'm experiencing some difficulties configuring our project with Maven and need some help :)

Say, I have a multi-module project, with modules A and B (there are ~20 others as well) but all of them inherit from some "root" pom.

I also have a custom maven plugin that should be enabled for module A only.

The plugin should run in the same way for all the modules, so I put the configuration in the root pom.

Now, the plugin is defined in the profile so that it will be activated only when I explicitly want so:

mvn test -PrunMyPlugin

this should work if I'm running this command from the root directory and if I'm running in the directory of module A. In module B the plugin shouldn't run regardless of this profile.

On the other hand

mvn test

should never invoke the plugin.

I've tried to use activation on property but it didn't work for me. I'm trying to avoid the situation when I need to configure the plugin for each concrete module and keep all the configurations in the root pom.

Could someone please provide any simple example of how to do that? Any help is highly appreciated.

Thanks in advance

Mark Bramnik
  • 39,963
  • 4
  • 57
  • 97
  • Possible duplicate of [this question](http://stackoverflow.com/questions/3532297/how-to-activate-a-maven-profile-in-a-dependent-module) – nobeh Apr 03 '12 at 07:53
  • I see some contradiction. First you say 'custom maven plugin that should be enabled for module A only', and then you say 'plugin should run in the same way for all the modules'. Can you post your `pom.xml` file so we could see what you're trying to achieve? – Andrew Logvinov Apr 03 '12 at 11:18
  • Yes, you right, I'm sorry, I just thought about the context where the plugin would be used. The plugin is supposed to be run in future with all the modules, but it will take time (may be months, till the modules code will be ready to run with this plugin, the project is really huge). So for now we've decided to upgrade modules one-by-one. Currently only module A is upgraded, so I would like to run this plugin for module A and all the rest "shouldn't see" this plugin altogether. – Mark Bramnik Apr 03 '12 at 11:42

2 Answers2

3

Defining a profile in a parent and then activating it from a child or from another profile is not supported by either Maven 2 or 3, currently. There are a couple of stackoverflow questions and answers [1] covering the details. There are related feature requests in Maven's issue tracker:

@Raghuram's suggestion to use <pluginManagement> is one way you can make this work without duplicating configuration. The other is to explicitly duplicate the config in each child module requiring it.

[1]: Activate different Maven profiles depending on current module? ; Why can't I activate a Maven2 profile from another profile?

Community
  • 1
  • 1
user944849
  • 14,524
  • 2
  • 61
  • 83
1

One of the ways to handle this requirement is to define your plugins within <pluginManagement> section of your multi-module parent pom. In each of the project where you need to use this plugin, you declare it.

This way, you get to define all the plugin details and configuration in a central place as well as have the flexibility to use it only for relevant modules. More details here.

Raghuram
  • 51,854
  • 11
  • 110
  • 122