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

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

Have more questions? Submit a request

2 Comments

  • 0
    Avatar
    Martin Todorov

    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 \
    -overwrite
    The example above would deploy a hello-world-1.0-SNAPSHOT.jar to the nexus-snapshots repository.

  • 0
    Avatar
    John Engelke

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

    According to your own documentation, at https://support.sonatype.com/entries/24431666 , 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?

Please sign in to leave a comment.
Powered by Zendesk