tags:

views:

100

answers:

2

Hi,

I am new bie to ivy.

  1. I am using packager resolver and that packager resolver resolves the zip file, unzip it, extracts the jar file from it in temp build file, but it stays temporarily and only the jar file which i specified as a module name gets copied to destination rest of all are ignored. Is there a way i can get all the jar files? I use preseverBuildDirectories but is there a better way to do it?

  2. Also is it possible for me to publish an artifact to svn using normal ivy? I got error while i was trying to use ivy 2.1.0 on XP using ant 1.8.0 java.illegalArguementException saying authorization failed. Is there a way i can work through ivy:publish?

  3. Is there a way i can use ivy variable in packager.xml?

Thanks in advance, Almas

A: 

1) Packager resolver

You need to include an ivy file for the repackaged module listing all the artifacts.

Here's my example that downloads the files associated with the Solr distribution

ivysettings.xml

<ivysettings>
    <settings defaultResolver="maven2"/>

    <caches defaultCacheDir="${user.home}/.ivy2/cache"/>

    <resolvers>
        <ibiblio name="maven2" m2compatible="true"/>

        <packager name="repackage" buildRoot="${user.home}/.ivy2/packager/build" resourceCache="${user.home}/.ivy2/packager/cache" preserveBuildDirectories="false">
            <ivy pattern="file:///${ivy.settings.dir}/packager/[organisation]/[module]/ivy-[revision].xml"/>
            <artifact pattern="file:///${ivy.settings.dir}/packager/[organisation]/[module]/packager-[revision].xml"/>
        </packager>
    </resolvers>

    <modules>
        <module organisation="org.apache.solr" name="solr" resolver="repackage"/>
    </modules>
</ivysettings>

Note how the packager resolver specifies a path to both an ivy and packager file.

The ivy file specifies the artifacts that are part of the package in the publications section.

packager/org.apache.solr/solr/ivy-1.4.0.xml

<ivy-module version="2.0">
    <info organisation="org.apache.solr" module="solr" revision="1.4.0"/>
    <configurations>
        <conf name="jars"    description="Jars released with SOLR distribution"/>
        <conf name="webapps" description="Web applications"/>
    </configurations>
    <publications>
        <!-- jars -->
        <artifact name="solr-cell" conf="jars"/>
        <artifact name="solr-clustering" conf="jars"/>
        <artifact name="solr-core" conf="jars"/>
        <artifact name="solr-dataimporthandler" conf="jars"/>
        <artifact name="solr-dataimporthandler-extras" conf="jars"/>

        <!-- webapps -->
        <artifact name="solr" type="war" conf="webapps"/>
    </publications>
</ivy-module>

The packager file contains the logic that copies out each artifact listed in the ivy file for the solr module.

packager/org.apache.solr/solr/packager-1.4.0.xml

<packager-module version="1.0">

    <property name="name" value="${ivy.packager.module}"/>
    <property name="version" value="${ivy.packager.revision}"/>

    <resource dest="archive" url="http://ftp.heanet.ie/mirrors/www.apache.org/dist/lucene/solr/1.4.0/apache-solr-1.4.0.tgz" sha1="521d4d7ce536dd16c424a11ae8837b65e6b7bd2d">
        <url href="http://www.apache.org/dist/lucene/solr/1.4.0/apache-solr-1.4.0.tgz"/&gt;
    </resource>

    <build>
        <!-- Jar artifacts -->
        <move file="archive/apache-${name}-${version}/dist/apache-${name}-cell-${version}.jar" tofile="artifacts/jars/${name}-cell.jar"/>
        <move file="archive/apache-${name}-${version}/dist/apache-${name}-clustering-${version}.jar" tofile="artifacts/jars/${name}-clustering.jar"/>
        <move file="archive/apache-${name}-${version}/dist/apache-${name}-core-${version}.jar" tofile="artifacts/jars/${name}-core.jar"/>
        <move file="archive/apache-${name}-${version}/dist/apache-${name}-dataimporthandler-${version}.jar" tofile="artifacts/jars/${name}-dataimporthandler.jar"/>
        <move file="archive/apache-${name}-${version}/dist/apache-${name}-dataimporthandler-extras-${version}.jar" tofile="artifacts/jars/${name}-dataimporthandler-extras.jar"/>

        <!-- War artifacts -->
        <move file="archive/apache-${name}-${version}/dist/apache-${name}-${version}.war" tofile="artifacts/wars/${name}.war"/>
    </build>

</packager-module>

2) Publish to subversion

I've never used it myself but I think you need to configure the subversion resolver and use this to publish your artifacts

3) Using ivy variable in packager file

The packager file listed above uses two ivy variables. Not sure what your question is.

Update: Supporting 3rd party jars

The publications section of the ivy file include the version number in the name of the 3rd party jar:

ivy file

..
<publications>
    <artifact name="abc-1.0" conf="jars"/>
    <artifact name="pqr-2.0" conf="jars"/>
</publications>
..

packager file

..
<build>
    <move file="archive/apache-${name}-${version}/dist/abc-1.0.jar" tofile="artifacts/jars/abc-1.0.jar"/>
    <move file="archive/apache-${name}-${version}/dist/pqr-2.0.jar" tofile="artifacts/jars/pqr-2.0.jar"/>
</build>
..
Mark O'Connor
A: 

Thanks for this. But in my zip file (with version 4.3.1) i have files like abc-1.0.jar pqr-2.0.jar xyz.jar

its failing to resolve the jars with version is it possible to somewhere i can specify version as well that would be latest.version beacuse the version of the jars above can change if i move from 4.3.1 to 4.3.2.

Two options. Include the version number in the name of the jar in the ivy file (See my updated anwser below). Of course another option is to add a dependency section in the ivy file so that the 3rd party jar is retrieved by ivy as normal.
Mark O'Connor