Search code examples
buildbuild-processivy

ivy report for entire repo?


I'm working on an internal ivy repository with a decent number of projects under it, each with many revisions. I would like to make a dependency report for the entire repository showing which versions of which artifacts depend on which revisions of other artifacts. Obviously it isn't too difficult to make a script to parse the published ivy xml files, but if this functionality exists already I'll use that. Something like the repreport task would be nice, but for a whole repo.

My main goal here is to get a report of artifacts that are not referenced by any other artifacts so as to make a list of candidates for removal from the repo.

So, does ivy have any way to build a dependency report against and entire repository?

Edit: Working through this, it looks like ivy:repreport is the way to go.

Here is my build.xml file:

<project name="Report Build" xmlns:ivy="antlib:org.apache.ivy.ant" basedir=".">
    <property name="ivy.version" value="2.2.0"/>
    <property name="ivy.home" value="${user.home}/.ivy2"/>

    <target name="fetch-ivy" unless="offline" description="Install Ivy if it doesn't already exist">
        <mkdir dir="${ivy.home}"/>
        <get
                src="http://repo2.maven.org/maven2/org/apache/ivy/ivy/${ivy.version}/ivy-${ivy.version}.jar"
                dest="${ivy.home}" usetimestamp="true"/>
    </target>

    <target name="init-ivy" depends="fetch-ivy" unless="ivy-initialized">
        <path id="ivy.lib.path">
            <fileset dir="${ivy.home}" includes="*.jar"/>
        </path>
        <taskdef resource="org/apache/ivy/ant/antlib.xml" uri="antlib:org.apache.ivy.ant" classpathref="ivy.lib.path"/>
        <property name="ivy-initialized" value="yes"/>
    </target>

    <target name="report" depends="init-ivy">
        <ivy:settings file="ivy-settings-report.xml" id="report.ivy.settings"/>
        <ivy:repreport settingsref="report.ivy.settings"/>
    </target>
</project>

And here is my ivy settings file:

<?xml version="1.0" encoding="UTF-8"?>
<ivy-settings>
    <settings defaultResolver="main"/>
    <resolvers>
        <chain name="main">
            <url name="internalartifacts" m2compatible="false">
                <artifact
                        pattern="http://internalartifacts.local/[organization]/[module]/[revision]/[artifact]-[revision](-[classifier]).[ext]"/>
                <ivy pattern="http://internalartifacts.local/[organization]/[module]/[revision]/ivy-[revision].xml"/>
            </url>
        </chain>
    </resolvers>
</ivy-settings>

Solution

  • The documentation for repreport says:

    To generate a xml report for all the latest versions of all the modules in your repository:

    <ivy:repreport />
    

    Limitation: this task requires to be able to browse the repository, and is thus limited to resolvers supporting repository listing. In particular, it means it doesn't work to report all organizations in a repository using m2compatible mode. Moreover, to be able to list organizations, this task requires an [organisation] token in the resolver(s) used.

    So this should totally work.

    As mentioned in the comment: It is important that your repository has ivy.xml files for the artifacts in it. Otherwise ivy cannot recognize the dependencies between the artifacts and your report will be empty.