Is there anyway to exclude artifacts inherited from a parent POM?

后端 未结 9 1230
礼貌的吻别
礼貌的吻别 2020-11-30 22:02

Artifacts from dependencies can be excluded by declaring an element inside a But in this case it\'s needed to

9条回答
  •  没有蜡笔的小新
    2020-11-30 22:45

    I really needed to do this dirty thing... Here is how

    I redefined those dependencies with scope test. Scope provided did not work for me.

    We use spring Boot plugin to build fat jar. We have module common which defines common libraries, for example Springfox swagger-2. My super-service needs to have parent common (it does not want to do so, but company rules force!)

    So my parent or commons has pom.

    
    
        
    
        
            
                io.springfox
                springfox-swagger2
                ${swagger.version}
                
                    
                        com.google.guava
                        guava
                    
                
            
            
                io.springfox
                springfox-swagger-ui
                ${swagger.version}
            
            
                io.springfox
                springfox-bean-validators
                ${swagger.version}
            
    
           
            
                junit
                junit
                ${junit.version}
            
            
                org.apache.poi
                poi-ooxml
                ${apache.poi.version}
            
        
    
    

    And my super-service pom.

    super-service
    
        com.company
        common
        1
    
    
    
    
        
    
        
            io.springfox
            springfox-swagger2
            test
        
        
            io.springfox
            springfox-bean-validators
            test
        
        
            io.springfox
            springfox-core
            2.8.0
            test
        
    
        
    
        
            org.springframework.boot
            spring-boot-starter-web
        
         
            junit
            junit
        
        
            org.apache.poi
            poi-ooxml
        
    
    

    This is size of the final fat artifact

    82.3 MB (86,351,753 bytes) - redefined dependency with scope test
    86.1 MB (90,335,466 bytes) - redefined dependency with scope provided
    86.1 MB (90,335,489 bytes) - without exclusion
    

    Also this answer is worth mentioning - I wanted to do so, but I am lazy... https://stackoverflow.com/a/48103554/4587961

提交回复
热议问题