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

前端 未结 4 1709
半阙折子戏
半阙折子戏 2020-11-29 04:49

I\'m looking for a general technique here, but let\'s give a specific example. I have a multi-module project and I\'d like to run the exec:java goal from the co

4条回答
  •  抹茶落季
    2020-11-29 05:04

    A somewhat general technique that I've used in this circumstance is to define a profile in the submodule POM in question that binds exec:java to the test phase. For example:

                                                                                                                          
                                                                                                                           
        test-java                                                                                                          
                                                                                                                             
                                                                                                                           
                                                                                                                            
              org.codehaus.mojo                                                                                  
              exec-maven-plugin                                                                            
              1.1.1                                                                                              
                                                                                                                        
                                                                                                                         
                  test                                                                                               
                                                                                                                             
                    java                                                                                               
                                                                                                                            
                                                                                                                     
                    com.foo.bar.MyClass                                                                      
                                                                                                                    
                                                                                                                        
                                                                                                                       
                                                                                                                           
                                                                                                                          
                                                                                                                            
                                                                                                                          
                                                                                                                         
    

    Then from the top of your project, run:

    mvn test -Ptest-java
    

    This will set up the inter-module classpath as usual, and attempt to run the test-java profile in all of your subprojects. But since only the one you care about has the profile defined, it's the only one that will do anything.

    It does take a wee bit of extra time for Maven to grind through your other subprojects NOOPing, but it's not so bad.

    One thing to note is that the subproject is run with the top-level directory as the current working directory (not the subproject directory). There's not much you can do to work around that, but hopefully that won't cause you trouble.

提交回复
热议问题