Can I force Maven 2 to require a property to be specified on the command line?

后端 未结 4 1067
被撕碎了的回忆
被撕碎了的回忆 2020-12-31 02:19

I\'m setting up a maven build, and the destination server needs to be specified on the command line as a property (which is then used to select the appropriate profile), eg<

4条回答
  •  执念已碎
    2020-12-31 02:59

    Maybe you could use such a workaround: in Maven you can activate a profile if some property is not set:

    
    ...
        
            
                failure_profile
                
                    
                        !env
                    
                
            
        
    
    

    Then you shall force this profile always fail, e.g. using maven-enforcer-plugin:

    
        failure_profile
        ...
        
            
              
                org.apache.maven.plugins
                maven-enforcer-plugin
                
                  
                    enforce
                    
                      enforce
                    
                    
                      
                        
                      
                      true
                    
                  
                
              
            
          
    
    

    If you don't provide -Denv build will then fail:

    [INFO] [enforcer:enforce {execution: enforce}]
    [WARNING] Rule 0: org.apache.maven.plugins.enforcer.AlwaysFail failed with message:
    Always fails!
    [INFO] ---------------------------------------------------------
    [ERROR] BUILD ERROR
    

    Well, it's much more verbose then Ant, but pure Maven :)

提交回复
热议问题