Maven profile for single module

前端 未结 2 1717
离开以前
离开以前 2021-02-15 22:18

I have a multi module maven project, which builds successfully, I\'d like to build just one of the modules I have. How would I do that with profiles ? I could d

2条回答
  •  隐瞒了意图╮
    2021-02-15 22:44

    To implement this with profiles, you could use two profiles, one with all modules and another one with the wanted module only. Something like this:

    
      
        all
        
          true
        
        
          module-1
          ...
          module-n
        
      
      
        module-2
        
          module-2
        
      
    
    

    And then call it like this:

    mvn -Pmodule-2 package
    

    Two things to note here:

    1. You need to move the from the POM in a "default" profile (because from a profile are only additive, they do not hide the modules declared in the POM).
    2. By marking it as , the "default" profile will be picked if nothing else is active but deactivated if something else is.

    One could even parametrize the name of the module and pass it as property:

    
      ...
      
        module-x
        
          
            module-name
          
        
        
          ${module-name}
        
      
    
    

    And invoke maven like this:

    mvn -Dmodule-name=module-2 package
    

    But this is a poor implementation IMHO, I prefer the -pl "advanced" reactor options (less xml, much more power and flexibility):

    mvn -pl module-2 package
    

提交回复
热议问题