can't activate profiles in multi

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


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:

  • https://issues.apache.org/jira/browse/MNG-3309
  • https://issues.apache.org/jira/browse/MNG-4565
  • https://issues.apache.org/jira/browse/MNG-5127
  • @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?


    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.

    链接地址: http://www.djcxy.com/p/10646.html

    上一篇: 架构/示例,用于使CoreData与Web同步

    下一篇: 无法激活多个配置文件