Managing multi-module dependencies with Maven assembly plugin

前端 未结 1 1579
自闭症患者
自闭症患者 2021-02-02 03:19

I use Maven assembly plugin to create an assembly for my multi-module project. There are two separate applications built from this multi-module project, each having a separate s

1条回答
  •  北恋
    北恋 (楼主)
    2021-02-02 03:36

    I've always had similar experiences using the assembly plugin with multi-module projects where the end result wasn't what I expected. I hope someone else can provide a more accurate answer as to why that's happening and how best to use those two concepts in tandem.

    That said, a possible work-around would be to have module1 and module2 generate their own assembly artifacts which contain their respective jars and dependencies. Then you can modify the assembly sub-module pom file to have dependencies on the generated distribution artifacts from its sibling modules and then unpack those into a new assembly.

    In both Module1 and Module2's pom files you can add an assembly plugin configuration to your package phase much like you did with the assembly sub-module.

      
        
          
            maven-assembly-plugin
            2.2.2
    
            
              
                make-assembly
                package
                
                  single
                
              
            
    
            
              
                src/main/assembly/descriptor.xml
              
            
          
        
      
    

    Module1 would have a src/main/assembly/descriptor.xml like this

    
      distribution
      false
    
      
        zip
      
    
      
        
          module1
          false
        
      
    
    

    And Module2 will have a similar src/main/assembly/descriptor.xml

    
      distribution
      false
    
      
        zip
      
    
      
        
          module2
          false
        
      
    
    

    Then in the assembly/pom.xml you would add the Module 1 and 2 zip artifacts as dependencies

      
        
          com.test.app
          module1
          1.0
          zip
          distribution
        
        
          com.test.app
          module2
          1.0
          zip
          distribution
        
      
    

    ...and trim up the assembly/src/main/assembly/descriptor.xml file to look like this

    
      distribution
      false
    
      
        dir
      
    
      
        
          false
          true
        
      
    
    
    

    Like I said this would be one possible work around and unfortunately adds a significant amount of additional XML configuration to your build process. But it works.

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