Is there a way to capture user input in maven and assign it to a maven property?

后端 未结 2 1110
清酒与你
清酒与你 2020-12-10 04:22
  1. Is there a way to pause the maven execution flow to provide a command prompt so user can input text.
  2. Then I would like the provided text to be stored in a ma
2条回答
  •  伪装坚强ぢ
    2020-12-10 05:00

    You can catch a user input using maven-antrun-plugin. The following example show how ask current user the new project version.

        
            change-version
            
                validate
                
                    
                        org.apache.maven.plugins
                        maven-antrun-plugin
                        1.7
                        
                            
                                catch-new-version
                                
                                    run
                                
                                validate
                                
                                    
                                        
                                        
                                    
                                    true
                                
                            
                        
                        
                            
                                org.apache.ant
                                ant
                                1.8.4
                            
                        
                    
                    
                        org.codehaus.mojo
                        versions-maven-plugin
                        1.3.1
                        
                            
                                set-new-version
                                
                                    set
                                
                                validate
                                
                                    false
                                    ${new-user-version}
                                
                            
                        
                    
                
            
        
    
    

    You can run this feature by calling :

    mvn -N -P change-version
    

    Some explanations :

    • The -N- option allow to not recurse into sub-projects.
    • Using org.apache.ant:ant:1.8.4 to avoid https://issues.apache.org/bugzilla/show_bug.cgi?id=51161
    • Using maven 3.0.4
    • Documentation: maven-antrun-plugin, Input Tag

提交回复
热议问题