Parent pom and microservices

后端 未结 6 1170
礼貌的吻别
礼貌的吻别 2020-12-14 16:23
  • We have several projects that are microservices, every project is independent (running on separate spring boot server, exposing rest services, using separate DB schema
6条回答
  •  独厮守ぢ
    2020-12-14 17:20

    The 'problem' with a multi-module parent pom is that, without complicated profiles, it locks the modules in the same release cycle (assuming you're using the Release Plugin, which you should be).

    The way I work with Maven is to have a parent pom that declares:

    • common dependencies (logging APIs, JUnit, etc).
    • common plugins.
    • all dependencies in the dependencyManagement section.
    • all plugins in the pluginManagement section.

    Each module delcares the parent pom as its parent but the parent knows nothing about the modules.

    The benefit of this comes from the last to two bullets above, the 'management' sections. Anything contained in a 'management' section needs to be redeclared in a module that wants to use a particular dependency or plugin.

    For example the parent might look like this:

    
    
      com.example
      parent
      1.0.00-SNAPSHOT
    
      ...
    
      
    
        
          org.slf4j
          slf4j-api
          1.7.7
        
    
        
          junit
          junit
          4.11
          test
                    
    
      
    
      
    
        
          commons-lang
          commons-lang
          2.6
                
    
        
          commons-collections
          commons-collections
          2.1
        
    
      
    
      
    
        
          org.apache.maven.plugins
          maven-compiler-plugin
          3.1
          
            1.8
            1.8
          
        
    
      
    
      
    
        
    
          
            org.apache.maven.plugins
            maven-assembly-plugin
            2.4
            
              false
              
                src/main/assembly/assembly.xml
              
            
            
              
                make-assembly
                package
                
                  single
                
              
            
          
    
        
    
      
    
    
    

    And the module might look like this:

    
    
      
        com.example
        parent
        1.0.00-SNAPSHOT
      
    
      com.example
      module
      1.0.00-SNAPSHOT
    
      
    
        
          commons-lang
          commons-lang          
                
    
      
    
      
    
        
          org.apache.maven.plugins
          maven-assembly-plugin
        
    
      
    
    
    

    The module would:

    • have dependencies on org.slf4j:slf4j-api:1.7.7:compile, junit:junit:4.11:test and commons-lang:commons-lang:2.6:compile.
    • has the plugin org.apache.maven.plugins:maven-assembly-plugin:2.4

提交回复
热议问题