Artifactory:使用 Ant 部署快照

Artifactory: Deploying Snapshots with Ant

我正在使用这些目标将我的工件从 Ant 构建部署到 Artifactory:

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

这适用于普通版本。我可以按预期在 Artifactory 上找到工件。即使像“1.9.0-devel-SNAPSHOT”这样的版本也能正常工作。

但是如果我使用包含“.SNAPSHOT”的版本(例如“1.9.0-devel.SNAPSHOT”),Artifactory 会添加一个时间戳。这可能看起来没什么大不了的,但出于这个原因,Artifactory 会填满快照,而旧快照不会被删除。 Artifactory 上的 Maven Snapshot Version Behavior 设置为 Nonunique,这样应该会阻止时间戳,但事实并非如此!

真的很奇怪,当使用“.SNAPSHOT”版本时,工件如何最终出现在存储库中,因为版本文件夹是正确的,但工件名称是错误的:

这是我的存储库配置:

到目前为止我找到的唯一主题是这个 (Artifactory Snapshot filename handling),但它并不直接适用于我的问题,因为我不需要任何时间戳。

我正在使用 Artifactory 3.8.0

任何帮助和解释将不胜感激

您可以将 Maven Snapshot Version Behavior 设置为 Deployer - 使用部署者发送的格式。
此外,您可以设置 max unique snapshots 的值以清理旧快照。值 0(默认值)表示对唯一快照的数量没有限制。

更新

唯一快照版本(时间戳)是由 Ant Maven 插件而非 Artifactory 创建的。 为了防止 Ant Maven 插件生成唯一的快照版本,您需要将 uniqueVersion 属性 的值设置为 false(默认为 true):

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

此外,如果您希望 Artifactory 将部署的版本识别为快照,您将需要使用新的 custom layout,它将“.SNAPSHOT”视为快照标识符。
最快的方法是复制 Maven 布局并使用 \.SNAPSHOT 作为集成修订模式。
创建新布局后,您还需要创建一个使用此布局的本地存储库。

如果您不需要 Artifactory 将此版本视为快照,您可以配置存储库以接受快照和发布的部署。