0
votes

I am deploying my Artifacts from an Ant build to Artifactory using these Targets:

<project name="myApp" default="main" basedir="." xmlns:artifact="antlib:org.apache.maven.artifact.ant">
.
.
.
<path id="maven-ant-tasks.classpath">
    <fileset refid="maven-ant-tasks.fileset" />
</path>
<typedef resource="org/apache/maven/artifact/ant/antlib.xml" uri="antlib:org.apache.maven.artifact.ant" classpathref="maven-ant-tasks.classpath" />

<target name="define-artifact-properties">
    <property name="artifact.group" value="my.org" />
    <property name="artifact.name" value="myApp" />
    <property name="artifact.version" value="1.9.0-devel.SNAPSHOT" />
    <property name="artifact.type" value="jar" />
    <property name="artifact.dir" value="${build.dir}/artifacts" />
    <property name="artifact.pom" value="${artifact.dir}/${artifact.name}-${artifact.version}.pom" />
</target>

<target name="copy-artifacts" depends="init, define-artifact-properties">
    <copy file="${server.jar}" tofile="${artifact.dir}/${artifact.name}-${artifact.version}-server.jar" overwrite="true" preservelastmodified="true" />
    <copy file="${dist.ear.dir}/${application.name}.depl" tofile="${artifact.dir}/${artifact.name}-${artifact.version}.depl" overwrite="true" preservelastmodified="true" />
    <copy file="${server.ear}" tofile="${artifact.dir}/${artifact.name}-${artifact.version}.ear" overwrite="true" preservelastmodified="true" />
    <copy file="${client.jar}" tofile="${artifact.dir}/${artifact.name}-${artifact.version}-client.jar" overwrite="true" preservelastmodified="true" />
    <copy file="${server.interfaces.jar}" tofile="${artifact.dir}/${artifact.name}-${artifact.version}-interfaces.jar" overwrite="true" preservelastmodified="true" />
    <copy file="${prozess.jar}" tofile="${artifact.dir}/${artifact.name}-${artifact.version}-prozess.jar" overwrite="true" preservelastmodified="true" />
    <copy file="${src.zip}" tofile="${artifact.dir}/${artifact.name}-${artifact.version}-sources.jar" overwrite="true" preservelastmodified="true" />
</target>

<!-- deploy-task for creating and writing a temporary pom-file and deploying the artifact beside this pom-file -->
<target name="release-artifacts" depends="init, define-artifact-properties, copy-artifacts">
    <fail message="Property 'artifactory.publish.url' muss fuer das Releasen ins Artifactory gesetzt sein!" unless="artifactory.publish.url" />
    <fail message="Property 'artifactory.publish.username' muss fuer das Releasen ins Artifactory gesetzt sein!" unless="artifactory.publish.username" />
    <fail message="Property 'artifactory.publish.password' muss fuer das Releasen ins Artifactory gesetzt sein!" unless="artifactory.publish.password" />

    <mkdir dir="${artifact.dir}" />

    <artifact:pom id="tmp.pom" groupid="${artifact.group}" artifactid="${artifact.name}" version="${artifact.version}" packaging="${artifact.type}" name="${artifact.name}" />
    <artifact:writepom pomRefId="tmp.pom" file="${artifact.pom}" />
    <artifact:deploy file="${artifact.dir}/${artifact.name}-${artifact.version}-server.jar">
        <remoteRepository url="${artifactory.publish.url}">
            <authentication username="${artifactory.publish.username}" password="${artifactory.publish.password}" />
        </remoteRepository>
        <attach file="${artifact.dir}/${artifact.name}-${artifact.version}.depl" type="depl" />
        <attach file="${artifact.dir}/${artifact.name}-${artifact.version}.ear" type="ear" />
        <attach file="${artifact.dir}/${artifact.name}-${artifact.version}-client.jar" classifier="client" type="jar" />
        <attach file="${artifact.dir}/${artifact.name}-${artifact.version}-interfaces.jar" classifier="interfaces.jar" type="jar" />
        <attach file="${artifact.dir}/${artifact.name}-${artifact.version}-prozess.jar" classifier="prozess.jar" type="jar" />
        <attach file="${artifact.dir}/${artifact.name}-${artifact.version}-sources.jar" classifier="sources" type="jar" />
        <pom file="${artifact.pom}" />
    </artifact:deploy>
</target>

This works fine with normal version. I can find the artifacts on Artifactory as expected. Even versions like "1.9.0-devel-SNAPSHOT" work just fine.

But if I use a version that contains ".SNAPSHOT" (for example "1.9.0-devel.SNAPSHOT") Artifactory adds a timestamp. This might not look like a big deal, but for that reason Artifactory fills up with Snapshots and old Snapshots are not getting deleted. The Maven Snapshot Version Behavior on Artifactory is set to Nonunique so that should prevent the timestamps, but it does not!

It is really strange, how the Artifacts end up in the Repository when using a ".SNAPSHOT"-version, because the Version Folder is correct, but the Artifactnames are wrong: enter image description here

Here is my repository configuration:

enter image description here

The only Topic I have found so far is this one (Artifactory Snapshot filename handling), but ist does not directly apply to my problem, because I don't want any Timestamps.

I am using Artifactory 3.8.0

Any help and explanations would be greatly appreciated

1

1 Answers

1
votes

You can set the Maven Snapshot Version Behavior to Deployer - use the format sent by the deployer as is.
In addition, you can set the value of max unique snapshots in order to clean older snapshots. A value of 0 (default) indicates that there is no limit on the number of unique snapshots.

Update

The unique snapshot version (timestamp) is created by the Ant Maven plugin and not Artifactory. To prevent the Ant Maven plugin from generating a unique snapshot version, you will need to set the value of the uniqueVersion property to false (default is true):

<artifact:deploy file="..." uniqueVersion="false">

In addition, if you would like Artifactory to identify the deployed version as a SNAPSHOT, you will need to use a new custom layout which will treat ".SNAPSHOT" as a snapshot identifier.
The fastest way to do it would be copying the Maven layout and using \.SNAPSHOT for the integration revision patterns.
After creating the new layout you will also need to create a local repository which use this layout.

If you do not need Artifactory to treat this version as a snapshot, you can configure the repository to accept deployments of both snapshots and releases.