Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven - can't activate profiles in multi-module project

Tags:

java

maven

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

like image 493
Mark Bramnik Avatar asked Apr 03 '12 07:04

Mark Bramnik


2 Answers

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?

like image 172
user944849 Avatar answered Oct 26 '22 10:10

user944849


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.

like image 39
Raghuram Avatar answered Oct 26 '22 10:10

Raghuram