Configure Ivy to dynamically download and install Ant extensions

Partho Sarathi

07 Apr, 2018 · 3 minutes read

  • Share:

We all know that Apache Antis a popular Java build management system. But, in many cases Ant alone is not enough for extended build tasks and we have to install Ant extensions or plugins. For example, tasks like – “loop through all the files available in a directory”, can be done quite easily using Ant-Contribextentions. For this, we have to download ant-contrib.jarto a directory, say /usr/share/ant-extensions/liband create a task definition in the Ant project file.

  
    
      
    
  

Complete Ant project file may look like:-

  
    
    
    
      
        
          
        
      
      
    
    
      
        
        
          
        
      
    
  

In the above example, we have to manually manage the dependencies and their versions. Well, there is a better solution using Apache Ivydependency manager wherein Ivy can automatically download Ant dependencies from maven repository. We just have to specify the name of the dependency along with it’s version in the Ant project file.

Ivy module dependencies can be described in an xml file called ivy.xml. ivy.xmlfile contains the description of the dependencies of a module, its published artifacts and its configurations. Sample ivy.xmlfile with only ant-contrib dependency may look like:-

  
    
    
      
    
  

We can also create this xml using echoxmlAnt task:-

  
    
      
      
        
      
    
  

We can specifiy multiple dependencies in ivy.xmland Ivy will make that dependencies available in the Ant task. The only jar file we have to include in the Ant task is ivy.jar, all other dependencies will be managed automatically by Ivy. We can also download ivy.jardynamically using the Ant getTask:-

  

At this point Ivy module dependencies has been configured. Ivy provides retrievetask, which then reads from ivy.xmland copies resolved dependencies in configurable file system location. Configure artifactpropertyfollowed by retrievetask which then sets loaded dependency in Ant property, which will be required to load dependencies using taskdefAnt task. retrieveand artifactpropertytask can be configured as:-

  
  

The ant-contribjar file will be loaded in Ant property ant-contrib.ant-contrib. Ivy not needed after this, now you can just load ant-contribtask using taskdefAnt task like this:-

  
    
      
    
  

With all the above things tied in together, the complete Ant(v1.9.4) project file looks like:-

  
    
    
    
    
    
      
      
    
    
      
        
          
        
      
    
    
      
        
      
      
      
        
          
          
            
          
        
      
      
    
    
      
      
    
    
      
        
          
        
      
      
    
    
      
        
        
          
        
      
    
  
  • Share:

The cleanest blogging platform


2024 © Maxotek. All rights reserved.