Maven module using spring-boot

前端 未结 2 1686
無奈伤痛
無奈伤痛 2021-02-01 02:39

I like to configure my applications in maven by creating modules like;

com.app
example-app
&l         


        
2条回答
  •  你的背包
    2021-02-01 03:07

    Another alternative, is to include in the parent pom, the parent declaration for spring boot, as shown in this post

    example-app pom.xml:

    
        
            org.springframework.boot
            spring-boot-starter-parent
            1.2.5.RELEASE
        
        4.0.0
        // rest of the example-app pom declarations
    
    

    After that, in the modules poms (app-web, app-impl, etc.), you declare example-app as parent, but now you can include the starter dependencies as you would normally do in a regular project.

    app-web pom.xml:

    
        
            org.demo
            example-app
            1.0-SNAPSHOT
        
        4.0.0
        app-web
        app-web
        1.0-SNAPSHOT 
        war
    
        
            
                org.demo
                app-api
                1.0-SNAPSHOT 
            
            
                org.demo
                app-impl
                1.0-SNAPSHOT 
            
            
                org.springframework.boot
                spring-boot-starter-web
            
            
                org.springframework.boot
                spring-boot-starter-tomcat
                provided
            
        
        // rest of the app-web pom declarations
    
    

    Regarding version management, what i used in these examples aren't exactly the best practices, but since is out of the scope of the question i skipped dependencyManagement and parent properties usage.

    Also, if there is a starter that is used in every module, you can declare the dependency in the parent pom and then all the modules will inherit it (for example spring-boot-starter-test)

提交回复
热议问题