How do I configure my Ivy build to deploy artifacts to Nexus Repository 2?

Visit 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):

  <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>

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"/>
<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"
                      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.

Have more questions? Submit a request


  • 0
    Permanently deleted user

    I think it would be a good idea, if you could further extend both Ivy examples to show how one could do things, if they're using Ivy as a standalone.

    For example, deployment would look something like:

    java -jar /path/to/ivy.jar \
    -settings /path/to/ivysettings.xml \
    -ivy ivy.xml \
    -publish nexus-snapshots \
    -publishpattern "target/[artifact]-[revision].[ext]" \
    -revision 1.0-SNAPSHOT \
    -status snapshot \
    The example above would deploy a hello-world-1.0-SNAPSHOT.jar to the nexus-snapshots repository.

  • 0
    Permanently deleted user

    Yes, but does it update the Maven Metadata in the Nexus repo?

    According to your own documentation, at , the Maven Deploy Plugin does all the work to increment and augment the maven-metadata.xml file. It seems if there is no timestamp, and there is no snapshot increment id (i.e. myArtifact-<date>.<time>-<increment\_id>.ext> then it's about as effective as using the release repo for absolutely everything.

    Does anyone know if the Nexus Maven Metadata is updated by this?

  • 0
    Peter Lynch

    We are closing this article for comments.

    If you have a support license, please contact us by submitting a support ticket.

    If you do not have a support license, please use our Nexus Users List or our other free support resources.

Article is closed for comments.