ANT:在构建jar中添加版本号的最简单方法是什么?

sta*_*low 3 java ant

<?xml version="1.0" encoding="UTF-8"?>
<project name="myPlugin" default="all">
<target name="artifact.myPlugin:jar" depends="init.artifacts, compile.module.myPlugin" description="Build &#39;myPlugin:jar&#39; artifact">
    <mkdir dir="${artifact.output.myplugin:jar}" />
    <jar destfile="${temp.jar.path.myPlugin.jar}" duplicate="preserve" filesetmanifest="mergewithoutmain">
        <zipfileset file="${basedir}/META-INF/MANIFEST.MF" prefix="META-INF" />
        <zipfileset dir="${myPlugin.output.dir}" />
    </jar>

<!--How would I add a version number to this that reflects my projects version -->
    <copy file="${temp.jar.path.myPlugin.jar}" tofile="${artifact.output.myPlugin:jar}/plugin.company.jar" />
</target>
Run Code Online (Sandbox Code Playgroud)

人们这样做的典型方式是什么?

示例(从上面拉出)

<copy file="${temp.jar.path.myPlugin.jar}" tofile="${artifact.output.myPlugin:jar}/plugin.company{version}.jar" />
Run Code Online (Sandbox Code Playgroud)

Mar*_*nor 7

最简单的解决方案是使用ANT buildnumber任务.

<project name="myPlugin" default="all">

    <property name="version" value="1.0"/>

    <target...
        <buildnumber/>

        <jar destfile="/path/to/jar/myjar-${version}.${build.number}.jar" ...
            ...
        </jar>
    </target>

</project>
Run Code Online (Sandbox Code Playgroud)

每个构建都将生成一个唯一的版本号:

  • myjar这一-1.0.0
  • myjar这一-1.0.1
  • myjar这一-1.0.2
  • ..