2

I have a maven project composed of several submodules.

Let's call the submodules shared and webapp. The project is normally built from the parent POM, which resides in the parent directory. So the directory layout looks like:

myproject/pom.xml
myproject/shared/pom.xml
myproject/webapp/pom.xml

I have a specific plugin that I want to be executable from the command line in the top-level directory. I do not want it to run by default in any phase. So usually I want to run mvn clean install, and the plugin should not execute at all in this case. But also I want to be able to say mvn clean install com.mycompany:myplugin:goal and the execution should run in this case, but the execution should only run once for the webapp submodule. The execution should not run either for the parent POM or for the shared submodule when I specify this on the command line.

The problem I have is that if I define the execution in the parent POM, it runs repeatedly for every submodule. If I define the execution in the webapp POM, it is not accessible through a command line invocation of Maven.

I want to do this in a single Maven comand and that single command must also be able to build & run phases for all submodules -- not just the webapp submodule -- hence the -pl command line option does not work for this case?

Related: Running a specific Maven plugin goal from the command line in a sub-module of a multi-module reactor project

Is such a thing possible? If it's impossible, I'll accept an answer stating that.

Community
  • 1
  • 1
amoe
  • 4,473
  • 4
  • 31
  • 51
  • 5
    Create a profile within the webapp an run it via the activated profile. Otherwise i didn't understand why you need to run this plugin from command line and within the build? – khmarbaise Mar 19 '14 at 12:09
  • @khmarbaise is right, that's absolutely what you want. Just create a separate profile in webapp, asign your goal to whatever phase you want, and then run mvn command from parent with defined profile. The -P options propagate even to submodules. – jholusa Mar 19 '14 at 12:44
  • The profile method worked very well to allow me to access the execution from the top-level POM -- thanks for that. However, I could not find a solution that allowed me to call the execution from the command line **without** binding it to a phase. I wonder if this is possible. – amoe Mar 24 '14 at 12:11

1 Answers1

1

The plugin has to be defined in the parent pom to be executable at the parent level. But if defined in the parent, the plugin is executed for all modules. Since this is your plugin (com.mycompany:myplugin), you can define a "no-op" configuration option in the plugin implementation. Then, in each pom where you want the plugin to do nothing, you use that configuration option.

As an example, the docker-maven-plugin does exactly that. If you use:

<configuration>
    <skipDocker>true</skipDocker>
</configuration>

the plugin will not execute for that pom.

Paulo Merson
  • 13,270
  • 8
  • 79
  • 72