I\'m trying to run exec-maven-plugin\'s exec:java goal on a simple two-module project where one module depends on the other. So far I can\'t find a
exec-maven-plugin to a maven lifecycle goal, say verify. module2, define the plugin configurations in the parent pom within pluginManagement. Use the same only in module 2. mvn verify -Dexec.mainClass=MyMain.
parent pom
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<phase>verify</phase>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
module 2
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
Goals in a multi-module project, when run from the parent, will run against all modules. I don't think that's what you want. You can try:
mvn exec:java -pl module2 -Dexec.mainClass=MyMain
That might work? More info:
However, I think it's more intuitive to change directory to the sub-module containing the executable before running it.
See this answer for a single-command alternative without mvn install:
https://stackoverflow.com/a/26448447/1235281
By using skip in the parent pom.xml, you can tell Maven to only run exec:java on a specific submodule.
GitHub: https://github.com/Oduig/mavenfiddle