Iterate over for loop with fixed amount of iterations

前端 未结 2 597

I am using ant-contrib library in my ant scripts, but I do not get how can I make a fixed amount of loops using foreach tag? By fixed amount of iterations I do not mean some

2条回答
  •  无人共我
    2021-01-20 04:31

    ANT is not a programming language and I'm not a fan of ant-contrib, which I think attempts to retrofit this feature...

    My recommendation is to embed a scripting language into your build. The advantage of javascript is that it won't require additional jars, but I think you'll discover the groovy ANT task is extremely powerful.

    Example

    $ ant -Dtimes=3
    
    loop:
    
    dosomething:
         [echo] hello world
    
    dosomething:
         [echo] hello world
    
    dosomething:
         [echo] hello world
    

    build.xml

    
    
      
    
      
        
    
        
          def count = properties.times.toInteger() 
    
          (1..count).each {
            ant.ant(target: "dosomething")
          }
        
      
    
      
        
      
    
    
    

    An extra "bootstrap" target could be added to install groovy jar dependency automatically

      
        
        
      
    

提交回复
热议问题