Artifactory:使用Ant部署快照

时间:2015-07-14 15:21:31

标签: maven ant artifactory

我使用这些目标将我的工件从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上找到工件。甚至像&#34; 1.9.0-devel-SNAPSHOT&#34;工作得很好。

但如果我使用的版本包含&#34; .SNAPSHOT&#34; (例如&#34; 1.9.0-devel.SNAPSHOT&#34;)Artifactory添加时间戳。这可能看起来不是什么大问题,但由于这个原因,Artifactory填满了快照,旧的快照不会被删除。 Artifactory上的Maven Snapshot Version Behavior设置为Nonunique,因此应该阻止时间戳,但它不会![/ p>

真的很奇怪,当使用&#34; .SNAPSHOT&#34; -version时,Artifacts如何在存储库中结束,因为Version Folder是正确的,但Artifactnames是错误的: enter image description here

这是我的存储库配置:

enter image description here

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

我正在使用Artifactory 3.8.0

非常感谢任何帮助和解释

1 个答案:

答案 0 :(得分: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将此版本视为快照,则可以将存储库配置为接受快照和版本的部署。