Visit my.sonatype.com for documentation on Nexus Repository version 2.
First, let's assume you have an Ant build that successfully loads the Ivy tasks as an antlib. You need to load some custom Ivy settings that tell Ivy where to publish artifacts (note that the realm must match this example):
<ivysettings>
<settings defaultResolver="nexus"/>
<credentials host="localhost" realm="Sonatype Nexus Repository Manager" username="deployment" passwd="deployment123"/> <publications>
<artifact name="simple-project" type="jar"/>
</publications> <property name="nexus-public" value="http://localhost:8081/nexus/content/groups/public"/> <property name="nexus-releases" value="http://localhost:8081/nexus/content/repositories/releases"/>
<property name="nexus-snapshots" value="http://localhost:8081/nexus/content/repositories/snapshots"/> <resolvers>
<ibiblio name="nexus" m2compatible="true" root="${nexus-public}"/> <ibiblio name="nexus-releases" m2compatible="true" root="${nexus-releases}"/>
<ibiblio name="nexus-snapshots" m2compatible="true" root="${nexus-snapshots}" checkmodified="true"
changingPattern="*-SNAPSHOT"/> </resolvers>
</ivysettings>
You can load these settings from your build with:
<ivy:settings file="ivysettings.xml" />
Here is the confusing part. Your project needs to explicitly define the artifacts it will publish in the publications element of your project's custom Ivy settings. In this case, the project defines a single "publication": simple-project of type "jar". This list of publications will be used later in this process during the publish task.
Next step is to verify that your ivy.xml file contains a valid organisation and (Ivy uses English spelling throughout the project). Here's and example of the first line of the ivy.xml file:
<ivy-module version="2.0">
<info organisation="com.example" module="simple-project" revision="1.0-SNAPSHOT"/>
<dependencies>
<dependency org="org.jbundle.util" name="org.jbundle.util.jbackup" rev="2.0.0"/> ... </dependencies> </ivy-module>
Once you've done this, you are ready to publish artifacts. You'll need to generate a pom.xml file prior to publishing. Run these four Ant tasks together, and you'll have successfully published an artifact to Nexus Repository 2 using Apache Ivy:
<ivy:deliver deliverpattern="${build.dir}/ivy.xml" pubrevision="${publish.revision}" status="release"/>
<ivy:makepom ivyfile="${build.dir}/ivy.xml" pomfile="${build.dir}/pom.xml"/>
<ivy:resolve/> <ivy:publish resolver="nexus-snapshots" revision="1.0-SNAPSHOT"
overwrite="true"
publishivy="false" >
<artifacts pattern="target/[artifact].[ext]"/>
</ivy:publish> </ivy:deliver>
After all of this configuration, you'll be able to publish a SNAPSHOT artifact, but Ivy doesn't support publishing SNAPSHOT artifacts with timestamps. If you needed to publish a release artifact, just change all the revisions to a release version number and switch the ivy:publish task to publish to nexus-releases.