emmby
emmby

Reputation: 100462

Maven targets in multimodule projects

I have a multi-module project with several subprojects, one of which uses the maven android plugin:

                  +-------------+ 
                  | Aggregator  |
                  |    Module   |
                  +-------------+ 

+-------------+   +-------------+   +-------------+ 
|  Module 1   |   |  Module 2   |   |  Module 3   |
|  (android)  |   |             |   |             |
+-------------+   +-------------+   +-------------+ 

I frequently run the following command from Module 1:

module-1 $ mvn clean install android:redeploy

This works fine because Module 1 has the android plugin declared in its pom.

It would be convenient for me to be able to run the same command, eg. mvn clean install android:redeploy, from the Aggregator module, and have maven know that it should run "clean" and "install" in all sub-modules, and "android:redeploy" only in the module(s) that support it, namely Module 1.

Instead, when I try to run the command from the aggregator module, I get an error that says "Error resolving version for plugin", which makes sense since it hasn't been declared in the aggregator, and in fact wouldn't make sense to be declared in the aggregator.

Is there a clever way I can configure my modules to just "do the right thing" in this situation so that I don't have to run maven in two separate directories?

Upvotes: 1

Views: 273

Answers (1)

bmargulies
bmargulies

Reputation: 100161

Add a pluginManagement clause for the plugin to the parent project.

When you put a <plugin/> element into <pluginManagement/>, it means that it provides the configuration for that plugin when it is needed, but does not instruct maven to run it.

You put a <skip>${skip-android}</skip> in that configuration (assuming that this plugin supports the standard pattern.

You set the skip-android property to true in the aggregator.

Then you configure the individual projects where it makes sense to set the skip-android property to false.

Upvotes: 1

Related Questions