You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ivy-user@ant.apache.org by Burt Leung <bu...@gmail.com> on 2009/12/16 01:50:16 UTC

Question about publishing snapshots to nexus

Hi All,

I've recently started studying IVY and am interested in using it in our own
development process. One of the problems I'm trying to solve is how to
publish a "snapshot" type artifact to our company's Sonatype Nexus
repository.

Actually, I did manage to publish and consume a snapshot of a dependency,
but I think there's something I'm not quite doing correctly. I'm hoping
someone can provide some guidance. Here is what I did:
1) In order to publish a jarFileA to Nexus I had to use the "makepom" ANT
task. This is because Nexus works with pom files and I'm not the server
admin so I can't dictate that we'll configure things to use ivy.xml
descriptor files instead (I'm just guessing that's possible, not sure).

1a) In the ivysettings.xml I defined the resolver for a release type
repository on the Nexus server:
<ibiblio name="localReleasesRepo" m2compatible="true" checkmodified="true"
root="http://localhost:8080/nexus-webapp-1.3.3/content/repositories/releases
"/>

1b) Here is the "info" section" in the ivy.xml (just showing for the sake of
the revision value):
    <info
        organisation="someOrg"
        module="someMod"
        revision="1.0.0"  <==========
        status="integration">
        <repository name="21CSINexus" url="
http://buildsvr.21csi.com:8081/nexus"/>
    </info>

1c) Here is what my ANT build target looks like for publishing a release:
    <target name="publishRelease" >
        <available property="isArtifactsDirCorrect" file="${artifactsDir}"/>
        <fail message="The directory is not valid: ${artifactsDir}"
unless="isArtifactsDirCorrect" />

        <ivy:makepom ivyfile="ivy.xml"
pomfile="${artifactsDir}/${ivyModule}.pom"/>  <====================

        <tstamp>
            <format property="now" pattern="yyyyMMddHHmmss"/>
        </tstamp>

        <ivy:publish resolver="localReleasesRepo"
settingsref="defaultSettings" organisation="${ivyOrg}"
            module="${ivyModule}" revision="${ivyModuleVersion}"
pubdate="${now}"
            forcedeliver="false" overwrite="true"
artifactspattern="${artifactsDir}/[artifact].[ext]"
            publishivy="false" status="release">
            <!-- need to specify that the pom file will be published too,
otherwise it won't be. -->
            <artifact name="${ivyModule}" type="pom" ext="pom"/>
        </ivy:publish>
    </target>

2) Now for a normal "release" version of the artifact(s), the above is
perfectly fine. It will publish to the release type repository. However, if
I want to publish a snapshot of the artifact, then I had to do the
following:

2a) In the ivysetting.xml I had to specify a snapshot type repository on
Nexus and also a changingPattern:
<ibiblio name="localSnapshotsRepo" m2compatible="true" checkmodified="true"
changingPattern="*-SNAPSHOT" root="
http://localhost:8080/nexus-webapp-1.3.3/content/repositories/snapshots"/>

2b) I had to create a _separate_ ivy.xml file (named ivy.integration.xml)
which had a revision value that indicated it was a snapshot:
    <info
        organisation="com.p21csi.aedgex"
        module="bathymetry"
        revision="1.0.0-SNAPSHOT" <=============================
        status="integration">
        <repository name="21CSINexus" url="
http://buildsvr.21csi.com:8081/nexus"/>
    </info>

2c) A separate ANT target for publishing a snapshot had to be created which
invoked the makepom operation on the ivy.integration.xml file:
    <target name="publishSnapshot" >
        <available property="isArtifactsDirCorrect" file="${artifactsDir}"/>
        <fail message="The directory is not valid: ${artifactsDir}"
unless="isArtifactsDirCorrect" />

        <!--<ivy:makepom ivyfile="ivy.xml"
pomfile="${artifactsDir}/${ivyModule}.pom"/>-->
        <ivy:makepom ivyfile="ivy.integration.xml"
pomfile="${artifactsDir}/${ivyModule}.pom"/> <============

        <tstamp>
            <format property="now" pattern="yyyyMMddHHmmss"/>
        </tstamp>

        <ivy:publish resolver="localSnapshotsRepo"
settingsref="defaultSettings" organisation="${ivyOrg}"
            module="${ivyModule}" revision="${ivyModuleVersion}"
            pubrevision="${ivyModuleVersion}-SNAPSHOT"
<================================
            pubdate="${now}"
            forcedeliver="true" overwrite="true"
artifactspattern="${artifactsDir}/[artifact].[ext]"
            publishivy="false" status="integration">
            <!-- need to specify that the pom file will be published too.
-->
            <artifact name="${ivyModule}" type="pom" ext="pom"/>
        </ivy:publish>
    </target>


So, while I did verify that I was able to publish the snapshot and then
consume it from a project that depended on that snapshot, is there a way to
do this without having to _duplicate_ the ivy.xml file?

Another issue I found is that the snapshot I published to nexus, using Ivy
and its generated POM file, is placed according to the following file system
structure:
<nexus server root directory>
    <snapshot repository folder>
        <artifactName>
            <versionNumber-SNAPSHOT>
                <artifactName>-1.0.0-SNAPSHOT.jar
                <artifactName>-1.0.0-SNAPSHOT.pom

Whereas, artifacts published using Maven are placed according to the
following file system structure:
<nexus server root directory>
    <snapshot repository folder>
        <artifactName>
            <versionNumber-SNAPSHOT>
                <artifactName>-1.0.0-<timestamp>.jar
                <artifactName>-1.0.0-<timestamp>.pom

How can I get the timestamp to be substituted when I publish artifacts?


Thanks in advance for any help that can be provided!
Burt

Re: Question about publishing snapshots to nexus

Posted by Matt Benson <gu...@gmail.com>.
I don't consider myself an expert here and I actually haven't had  
time to digest your entire original post, but I wanted to point out  
that if you're just using Nexus because it's convenient and you don't  
need to support Maven itself, you don't have to publish POMs at all.   
I have been happily publishing Ivy files to Nexus for several months  
now.

-Matt

On Dec 16, 2009, at 5:00 PM, Burt Leung wrote:

> For the issue where published "snapshots" did not appear in the Nexus
> repository with timestamp postfixes to files, I did find a sort of  
> "best
> practice" guideline that validates this behavior.
>
> A response on Stack Overflow seemed to support "non-unique" snapshots:
> http://stackoverflow.com/questions/1243574/how-to-stop-maven- 
> artifactory-from-keeping-snapshots-with-timestamps
>
> So maybe not having timestamped snapshots is okay after all. It  
> doesn't
> quite answer the question I originally posted but I'm fine with this
> behavior now (unless someone has some other suggestion/input).
>
> Also, I guess for now I'm just going to have to implement two IVY  
> files, one
> for the snapshots and one for the releases (since I need two  
> different pom
> files when publishing). If there is a better way please let me  
> know. :)
>
> Thanks!


Re: Question about publishing snapshots to nexus

Posted by Burt Leung <bu...@gmail.com>.
For the issue where published "snapshots" did not appear in the Nexus
repository with timestamp postfixes to files, I did find a sort of "best
practice" guideline that validates this behavior.

A response on Stack Overflow seemed to support "non-unique" snapshots:
http://stackoverflow.com/questions/1243574/how-to-stop-maven-artifactory-from-keeping-snapshots-with-timestamps

So maybe not having timestamped snapshots is okay after all. It doesn't
quite answer the question I originally posted but I'm fine with this
behavior now (unless someone has some other suggestion/input).

Also, I guess for now I'm just going to have to implement two IVY files, one
for the snapshots and one for the releases (since I need two different pom
files when publishing). If there is a better way please let me know. :)

Thanks!

Re: Question about publishing snapshots to nexus

Posted by Burt Leung <bu...@gmail.com>.
Thank you very much for your help Maarten!

I was successful at using the ivy:deliver task to generate an ivy.xml file
with the specifications that I required. Here is an excerpt of my (revised)
task for publishing snapshots to the Nexus repository:
=====================================
<target name="publishSnapshot">
    <available property="isArtifactsDirCorrect" file="${artifactsDir}"/>
    <fail message="The directory is not valid: ${artifactsDir}"
          unless="isArtifactsDirCorrect" />

    <!-- since we are publishing a snapshot, the ivy.xml file needs to have
a
         special revision value that is postfixed with "-SNAPSHOT"
         (a Maven convention). we use the IVY deliver task to create a
special
         copy of the ivy.xml file with the snapshot revision value. -->
    <property name="generatedIVYFile" value="${artifactsDir}/ivy.xml"/>
    <ivy:deliver deliverpattern="${generatedIVYFile}"
        settingsref="defaultSettings"
        organisation="${ivyOrg}" module="${ivyModule}" status="integration"
        revision="${ivyModuleVersion}"
        pubrevision="${ivyModuleVersion}-SNAPSHOT" />

    <!-- must do an IVY "resolve" operation on the generated IVY file. this
is
         because it creates a special file named
"resolved-[org]-[revision].xml"
         in the local IVY cache. this file is checked for by the IVY
framework
         before it proceeds and fails if it does not find the file. -->
    <property name="resolveIVYFile" value="${generatedIVYFile}"/>
    <antcall target="resolveInternal"/>

    <!-- generate the Maven POM file that will be uploaded to the
         repository. -->
    <ivy:makepom ivyfile="${generatedIVYFile}"
        pomfile="${artifactsDir}/${ivyModule}.pom"/>

    <ivy:publish resolver="SnapshotsRepo" settingsref="defaultSettings"
        organisation="${ivyOrg}" module="${ivyModule}"
        revision="${ivyModuleVersion}-SNAPSHOT" pubdate="now"
        overwrite="true" artifactspattern="${artifactsDir}/[artifact].[ext]"

        publishivy="false" status="integration">
        <!-- need to specify that the pom file will be published too. -->
        <artifact name="${ivyModule}" type="pom" ext="pom"/>
    </ivy:publish>
</target>
=====================================


As you suggested, I created a new Jira (improvement) issue for implementing
timestamped snapshots. This new Jira issue is at
https://issues.apache.org/jira/browse/IVY-1153




On Wed, Dec 16, 2009 at 1:22 PM, Maarten Coene <ma...@yahoo.com>wrote:

> To solve your problem of having to duplicate the ivy.xml, you might want to
> deliver your ivy.xml file first to a temporary location.
> With the ivy:deliver task, you can set the revision of the delivered
> ivy.xml file, and in addition, ivy:deliver can optionally replace all
> dynamic revisions with static ones. This can avoid problems because maven
> won't understand revisions like for instance "latest.integration".
>
> After that, you can use the ivy:makepom task to transform your delivered
> ivy.xml file into a pom file.
>
> Another approach could be that you specify the revision in your ivy.xml as
> an ant property? Ivy will replace such properties when parsing the ivy.xml
> file...
>
> I don't know how to solve your second problem though. I think Ivy can
> download these kind of timestamped snapshots, but it probably can't publish
> them this way. Maybe you could open a JIRA improvement request for this? Or
> maybe you can add those timestamped artifacts as extra <artifact> element to
> your ivy:publish task?
>
> Maarten
>

Re: Question about publishing snapshots to nexus

Posted by Maarten Coene <ma...@yahoo.com>.
To solve your problem of having to duplicate the ivy.xml, you might want to deliver your ivy.xml file first to a temporary location.
With the ivy:deliver task, you can set the revision of the delivered ivy.xml file, and in addition, ivy:deliver can optionally replace all dynamic revisions with static ones. This can avoid problems because maven won't understand revisions like for instance "latest.integration".

After that, you can use the ivy:makepom task to transform your delivered ivy.xml file into a pom file.

Another approach could be that you specify the revision in your ivy.xml as an ant property? Ivy will replace such properties when parsing the ivy.xml file...

I don't know how to solve your second problem though. I think Ivy can download these kind of timestamped snapshots, but it probably can't publish them this way. Maybe you could open a JIRA improvement request for this? Or maybe you can add those timestamped artifacts as extra <artifact> element to your ivy:publish task?

Maarten




----- Original Message ----
From: Burt Leung <bu...@gmail.com>
To: ivy-user@ant.apache.org
Cc: Bruce Harris <br...@21csi.com>
Sent: Wed, December 16, 2009 1:50:16 AM
Subject: Question about publishing snapshots to nexus

Hi All,

I've recently started studying IVY and am interested in using it in our own
development process. One of the problems I'm trying to solve is how to
publish a "snapshot" type artifact to our company's Sonatype Nexus
repository.

Actually, I did manage to publish and consume a snapshot of a dependency,
but I think there's something I'm not quite doing correctly. I'm hoping
someone can provide some guidance. Here is what I did:
1) In order to publish a jarFileA to Nexus I had to use the "makepom" ANT
task. This is because Nexus works with pom files and I'm not the server
admin so I can't dictate that we'll configure things to use ivy.xml
descriptor files instead (I'm just guessing that's possible, not sure).

1a) In the ivysettings.xml I defined the resolver for a release type
repository on the Nexus server:
<ibiblio name="localReleasesRepo" m2compatible="true" checkmodified="true"
root="http://localhost:8080/nexus-webapp-1.3.3/content/repositories/releases
"/>

1b) Here is the "info" section" in the ivy.xml (just showing for the sake of
the revision value):
    <info
        organisation="someOrg"
        module="someMod"
        revision="1.0.0"  <==========
        status="integration">
        <repository name="21CSINexus" url="
http://buildsvr.21csi.com:8081/nexus"/>
    </info>

1c) Here is what my ANT build target looks like for publishing a release:
    <target name="publishRelease" >
        <available property="isArtifactsDirCorrect" file="${artifactsDir}"/>
        <fail message="The directory is not valid: ${artifactsDir}"
unless="isArtifactsDirCorrect" />

        <ivy:makepom ivyfile="ivy.xml"
pomfile="${artifactsDir}/${ivyModule}.pom"/>  <====================

        <tstamp>
            <format property="now" pattern="yyyyMMddHHmmss"/>
        </tstamp>

        <ivy:publish resolver="localReleasesRepo"
settingsref="defaultSettings" organisation="${ivyOrg}"
            module="${ivyModule}" revision="${ivyModuleVersion}"
pubdate="${now}"
            forcedeliver="false" overwrite="true"
artifactspattern="${artifactsDir}/[artifact].[ext]"
            publishivy="false" status="release">
            <!-- need to specify that the pom file will be published too,
otherwise it won't be. -->
            <artifact name="${ivyModule}" type="pom" ext="pom"/>
        </ivy:publish>
    </target>

2) Now for a normal "release" version of the artifact(s), the above is
perfectly fine. It will publish to the release type repository. However, if
I want to publish a snapshot of the artifact, then I had to do the
following:

2a) In the ivysetting.xml I had to specify a snapshot type repository on
Nexus and also a changingPattern:
<ibiblio name="localSnapshotsRepo" m2compatible="true" checkmodified="true"
changingPattern="*-SNAPSHOT" root="
http://localhost:8080/nexus-webapp-1.3.3/content/repositories/snapshots"/>

2b) I had to create a _separate_ ivy.xml file (named ivy.integration.xml)
which had a revision value that indicated it was a snapshot:
    <info
        organisation="com.p21csi.aedgex"
        module="bathymetry"
        revision="1.0.0-SNAPSHOT" <=============================
        status="integration">
        <repository name="21CSINexus" url="
http://buildsvr.21csi.com:8081/nexus"/>
    </info>

2c) A separate ANT target for publishing a snapshot had to be created which
invoked the makepom operation on the ivy.integration.xml file:
    <target name="publishSnapshot" >
        <available property="isArtifactsDirCorrect" file="${artifactsDir}"/>
        <fail message="The directory is not valid: ${artifactsDir}"
unless="isArtifactsDirCorrect" />

        <!--<ivy:makepom ivyfile="ivy.xml"
pomfile="${artifactsDir}/${ivyModule}.pom"/>-->
        <ivy:makepom ivyfile="ivy.integration.xml"
pomfile="${artifactsDir}/${ivyModule}.pom"/> <============

        <tstamp>
            <format property="now" pattern="yyyyMMddHHmmss"/>
        </tstamp>

        <ivy:publish resolver="localSnapshotsRepo"
settingsref="defaultSettings" organisation="${ivyOrg}"
            module="${ivyModule}" revision="${ivyModuleVersion}"
            pubrevision="${ivyModuleVersion}-SNAPSHOT"
<================================
            pubdate="${now}"
            forcedeliver="true" overwrite="true"
artifactspattern="${artifactsDir}/[artifact].[ext]"
            publishivy="false" status="integration">
            <!-- need to specify that the pom file will be published too.
-->
            <artifact name="${ivyModule}" type="pom" ext="pom"/>
        </ivy:publish>
    </target>


So, while I did verify that I was able to publish the snapshot and then
consume it from a project that depended on that snapshot, is there a way to
do this without having to _duplicate_ the ivy.xml file?

Another issue I found is that the snapshot I published to nexus, using Ivy
and its generated POM file, is placed according to the following file system
structure:
<nexus server root directory>
    <snapshot repository folder>
        <artifactName>
            <versionNumber-SNAPSHOT>
                <artifactName>-1.0.0-SNAPSHOT.jar
                <artifactName>-1.0.0-SNAPSHOT.pom

Whereas, artifacts published using Maven are placed according to the
following file system structure:
<nexus server root directory>
    <snapshot repository folder>
        <artifactName>
            <versionNumber-SNAPSHOT>
                <artifactName>-1.0.0-<timestamp>.jar
                <artifactName>-1.0.0-<timestamp>.pom

How can I get the timestamp to be substituted when I publish artifacts?


Thanks in advance for any help that can be provided!
Burt