Normally, when we download jars from Ivy, we set pattern to include the version number of the jar.

<ivy:retrieve
    pattern="${lib.dir}/[conf]/[artifact]-[revision].[ext]"
    log="${ivy.log}"/>

However, for this one project, we can't do that. Jars have to be downloaded without version ID on them:

<ivy:retrieve
    pattern="${lib.dir}/[conf]/[artifact].[ext]"/>

This app is installed by overwriting what is already there. If a revision of a particular jar gets changed from one release to the next, we would end up with both the older jar and the newer version of that jar, and we would not know which version was being used. Removing the revision information makes it easy to make sure that older jars are replaced with the newer version.

However, the developer would still like a simple report on what versions of the jars were downloaded and put into the built war, so how can I generate such a report. I was looking at ivy:report but it doesn't produce a text report. There's a <ivy:artifactreport/> task, but that also produces an XML report and not a text report.

I could parse this report using Perl or Python, but I'd rather not use an executable as part of the build process. Otherwise, when a developer does a build, they'll have to make sure these external programs are correctly installed and configured.

Is there an easy way to produce a plain text report?

有帮助吗?

解决方案

Uses the ANT xslt task to generate a CSV formatted text file

Example

├── build
│   └── ivy
│       ├── com.myspotontheweb-demo-compile.html
│       ├── com.myspotontheweb-demo-runtime.html
│       ├── com.myspotontheweb-demo-test.html
│       ├── ivy-report.css
│       ├── report.txt
│       └── report.xml
├── build.xml
├── ivy.xml
└── report.xsl

build.xml

<project name="demo" default="resolve" xmlns:ivy="antlib:org.apache.ivy.ant">

    <target name="resolve" description="Use ivy to resolve dependencies">
        <ivy:resolve/>

        <!-- Reports -->
        <ivy:report todir='build/ivy' graph='false' xml='false'/>

        <ivy:artifactreport tofile="build/ivy/report.xml"/>
        <xslt style="report.xsl" in="build/ivy/report.xml" out="build/ivy/report.txt"/>

    </target>

</project>

report.xsl

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:output method="text"/>

  <xsl:template match="/">
    <xsl:apply-templates select="modules/module/artifact"/>
  </xsl:template>

  <xsl:template match="artifact">
    <xsl:value-of select="../@organisation"/>
    <xsl:text>,</xsl:text>
    <xsl:value-of select="../@name"/>
    <xsl:text>,</xsl:text>
    <xsl:value-of select="../@rev"/>
    <xsl:text>,</xsl:text>
    <xsl:value-of select="origin-location"/>
    <xsl:text>,</xsl:text>
    <xsl:value-of select="cache-location"/>
    <xsl:text>
</xsl:text>
  </xsl:template>

</xsl:stylesheet>

report.txt

org.slf4j,slf4j-api,1.7.5,http://repo1.maven.org/maven2/org/slf4j/slf4j-api/1.7.5/slf4j-api-1.7.5.jar,/home/mark/.ivy2/cache/org.slf4j/slf4j-api/jars/slf4j-api-1.7.5.jar
org.slf4j,slf4j-log4j12,1.7.5,http://repo1.maven.org/maven2/org/slf4j/slf4j-log4j12/1.7.5/slf4j-log4j12-1.7.5.jar,/home/mark/.ivy2/cache/org.slf4j/slf4j-log4j12/jars/slf4j-log4j12-1.7.5.jar
log4j,log4j,1.2.17,http://repo1.maven.org/maven2/log4j/log4j/1.2.17/log4j-1.2.17.jar,/home/mark/.ivy2/cache/log4j/log4j/bundles/log4j-1.2.17.jar
junit,junit,4.11,http://repo1.maven.org/maven2/junit/junit/4.11/junit-4.11.jar,/home/mark/.ivy2/cache/junit/junit/jars/junit-4.11.jar
org.hamcrest,hamcrest-core,1.3,http://repo1.maven.org/maven2/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar,/home/mark/.ivy2/cache/org.hamcrest/hamcrest-core/jars/hamcrest-core-1.3.jar
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top