Maven exec:java goal on a multi-module project

前端 未结 3 1616
星月不相逢
星月不相逢 2020-12-05 13:05

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

相关标签:
3条回答
  • 2020-12-05 13:23
    • You should bind the exec-maven-plugin to a maven lifecycle goal, say verify.
    • Since you want the plugin to be executed only for module2, define the plugin configurations in the parent pom within pluginManagement. Use the same only in module 2.
    • Then run the following:

    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>
    
    0 讨论(0)
  • 2020-12-05 13:34

    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:

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

    However, I think it's more intuitive to change directory to the sub-module containing the executable before running it.

    0 讨论(0)
  • 2020-12-05 13:36

    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

    0 讨论(0)
提交回复
热议问题