Monday, May 30, 2011

How to print Ivy's cachepath one artifiact per line with Ant

Many moons ago one Andrew Beacock shared how to use to dump out a classpath in a human-readable fashion (see http://blog.andrewbeacock.com/2005/08/pretty-printing-java-classpaths-using.html). The amount of Ant pain this gem saved me back in the day is ... well a lot.

Fast forward to 2011 and we're using Ant with Ivy as our dependency manager. We use Ivy's retrieve Ant task to get our artifacts but how do we print out a simple list of what Ivy got for us? Well, it turns out cachepath can get this for us, optionally filtered if we see fit:

<!-- after a resolve; in our case this target depends on our resolving target -->
    <ivy:cachepath pathid="ivy.cachepath" settingsRef="ivy.settings" />
    <pathconvert pathsep="${line.separator}  "
                 property="dependency.list"
                 refid="ivy.cachepath"/>
    <echo>DEPENDENCY LIST</echo>
    <echo>  ${dependency.list}</echo>

This will print something along the lines of:

[echo]   C:\...\.ivy2\cache\org.slf4j\slf4j-api\jars\slf4j-api-1.6.1.jar
     [echo]   C:\...\.ivy2\cache\org.slf4j\jcl-over-slf4j\jars\jcl-over-slf4j-1.6.1.jar
     [echo]   C:\...\.ivy2\cache\org.slf4j\log4j-over-slf4j\jars\log4j-over-slf4j-1.6.1.jar
     [echo]   C:\...\.ivy2\cache\ch.qos.logback\logback-classic\jars\logback-classic-0.9.28.jar
     [echo]   C:\...\.ivy2\cache\ch.qos.logback\logback-core\jars\logback-core-0.9.28.jar

Once in a while this is a lifesaver as it makes it easy to see a simple list of our dependencies. Since we print it out line-by-line it's now nice and easy to grep through and find specific things. Like say what version of the components in such and such a group we are getting.

3 comments:

The Qb Payroll said...

Our QuickBooks Support Phone Number Texas 1-833-325-0220, for further queries and get them addressed simultaneously. Our technicians are available by 24*7, round-the-clock. So, Why Delay? Call right now!! Read More: https://tinyurl.com/y7tgywml

Gouse said...

"Excellent tutorial! Your step-by-step guide on printing Ivy's cachepath with each artifact on a separate line is incredibly useful. This approach not only improves readability but also simplifies the process of managing dependencies. I appreciate the clear examples you provided, which make it easy to follow along. It would be great to see more tips on optimizing Ivy configurations or handling conflicts in dependencies. Thanks for sharing this valuable insight!"

Digital Marketing Course In Ameerpet

Gouse said...

"Thanks for this informative article! The step-by-step instructions on printing Ivy's cachepath with one artifact per line using Ant are incredibly helpful. It simplifies what can often be a confusing process. I especially appreciate the clear examples you provided. It would be great to see some additional tips on troubleshooting common issues that might arise during implementation. Overall, a fantastic resource for anyone working with Ivy and Ant!"

Digital Marketing Course In Hyderabad

Post a Comment