How do I tell Maven to use the latest version of a dependency?

前端 未结 12 731
慢半拍i
慢半拍i 2020-11-21 11:37

In Maven, dependencies are usually set up like this:


  wonderful-inc         


        
12条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2020-11-21 12:32

    Sometimes you don't want to use version ranges, because it seems that they are "slow" to resolve your dependencies, especially when there is continuous delivery in place and there are tons of versions - mainly during heavy development.

    One workaround would be to use the versions-maven-plugin. For example, you can declare a property:

    
        1.1.1
    
    

    and add the versions-maven-plugin to your pom file:

    
        
            
                org.codehaus.mojo
                versions-maven-plugin
                2.3
                
                    
                        
                            myname.version
                            
                                
                                    group-id
                                    artifact-id
                                    latest
                                
                            
                        
                    
                
            
        
    
    

    Then, in order to update the dependency, you have to execute the goals:

    mvn versions:update-properties validate
    

    If there is a version newer than 1.1.1, it will tell you:

    [INFO] Updated ${myname.version} from 1.1.1 to 1.3.2
    

提交回复
热议问题