tags:

views:

35

answers:

1

I am using Ivy to publish a snapshot of a built Jar to a locally hosted Nexus repository using the following Ant target.

<target name="publish">
    <ivy:publish resolver="nexus_snapshot" pubrevision="SNAPSHOT" overwrite="true">
        <artifacts pattern="${dist.dir}/[artifact].[ext]" />
    </ivy:publish>
</target>

This appears to work fine, resulting in the Jar and its associated ivy.xml being present in the repository (with filenames mymodule-SNAPSHOT.jar and ivy-SNAPSHOT.jar).

Later, in another build script, I wish to retrieve the Jar and its associated dependencies (i.e. as specified in its ivy.xml) into a directory.

This is the Ant target I'm using.

<target name="deploy">
 <delete dir="deploy" />
 <mkdir dir="deploy" />
 <ivy:settings file="${ivy.dir}/ivy_deploy_settings.xml" />
 <ivy:retrieve organisation="myorg" module="mymodule" 
  inline="true" revision="SNAPSHOT" pattern="deploy/[artifact].[ext]"/>
</target>

This retrieves the Jar to the directory, but not its dependencies. Also, if I add

conf="impl"

to the retrieve, it fails as the configuration is not found.

As such, it seems that the retrieve is simply not referencing the ivy.xml and hence not resolving the dependencies.

Should this work or am I misunderstanding something?

+2  A: 

I have now resolved this problem. I believe the issue is simply that Nexus works using POM files rather than Ivy files (by default at least - I can't see any relevant configuration options).

The solution is therefore to generate a suitable POM and publish this along with the Jar.

<target name="publish">
    <property name="generated.ivy.file" value="${dist.dir}/ivy.xml" /> 
    <ivy:deliver deliverpattern="${generated.ivy.file}"
        organisation="${ivy.organisation}" 
        module="${ivy.module}" status="integration"
        revision="${ivy.revision}"
        pubrevision="SNAPSHOT"
        conf="impl" />

<ivy:makepom ivyfile="${generated.ivy.file}" 
    pomfile="${dist.dir}/${ivy.module}.pom"/>

    <ivy:publish resolver="nexus_snapshot" pubrevision="SNAPSHOT" 
        publishivy="false" status="integration" overwrite="true">
        <artifacts pattern="${dist.dir}/[artifact].[ext]" /> 
        <artifact name="${ivy.module}" type="pom" ext="pom"/>
    </ivy:publish> 
</target>

Note that I first generate an Ivy file for the current module (and my desired configuration) to create the POM from.

William
You could just add the pom file to your list of published artifacts, in the ivy.xml file. In this way the publish task would pick it up using the artifacts pattern attribute
Mark O'Connor