【问题标题】:Artifactory: Deploying Snapshots with AntArtifactory:使用 Ant 部署快照
【发布时间】:2015-07-14 15:21:31
【问题描述】:

我正在使用这些目标将我的 Artifacts 从 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 快照版本行为设置为 Nonunique,这样应该可以防止时间戳,但它不会!

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

这是我的存储库配置:

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

我正在使用 Artifactory 3.8.0

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

【问题讨论】:

    标签: maven ant artifactory


    【解决方案1】:

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

    更新

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

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

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

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

    【讨论】:

    • 这无济于事,也不是我想要的。首先它没有帮助,因为即使我将行为设置为 Deployer 并将限制设置为 2,我也可以部署 3 次并拥有 3 倍的工件(如果我让它像这样运行,我的 Artifactory 很快就会充满快照)。第二:这不是我想要的,因为我不想要时间戳。
    猜你喜欢
    • 1970-01-01
    • 2020-12-08
    • 2022-10-07
    • 1970-01-01
    • 1970-01-01
    • 2018-05-31
    • 1970-01-01
    • 1970-01-01
    • 2015-12-25
    相关资源
    最近更新 更多